Files
wnmj/Classes/Games/DaZha/DZ_GameScene.cpp
2026-03-01 13:48:24 +08:00

2940 lines
81 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "DZ_GameScene.h"
#include "DZ_GamePlayer.h"
#include "DZ_GameLogic.h"
#include "UserInfo.h"
#include "MainScene.h"
#include "MissionWeiXin.h"
#include "DismissScene.h"
#include "DZ_SmallCardSprite.h"
#include "DZ_BigCardSprite.h"
#include "PopScene.h"
#include "ActionEx.h"
#include "JniFun.h"
#include "SetScene.h"
//#include "ChatScene.h"
#include "PlayerScene.h"
#include "IpTipScene.h"
#include "SimpleAudioEngine.h"
#include "editor-support/cocostudio/CCComExtensionData.h"
using namespace cocostudio;
using namespace DZ_SPACE;
//更多出牌按钮;
#define MOVE_BTN_OUT_CARD_COUNT 5
static CART_TYPE g_MoveBtnOutCards[MOVE_BTN_OUT_CARD_COUNT] = { DZ_CT_THREE_TAKE_TWO, DZ_CT_SINGLE_LINE, DZ_CT_DOUBLE_LINE, DZ_CT_THREE_LINE, DZ_CT_BOMB_4 };
bool DZGameScene::init()
{
if (!GameFrameBase::init())
{
return false;
}
m_cbTimeOutCard = 20;
m_cbTimeCallScore = 30;
m_cbTimeStartGame = 30;
m_cbTimeHeadOutCard = 20;
m_bNobodyCall = false;
m_cbLastOutCardType = DZ_CT_ERROR;
m_nSort = DZ_ST_ORDER;
m_nCellScore = 0;
m_nVoiceTimeID = 0;
m_strGameRuleInfo = "";
zeromemory(m_aryTempCardCount, sizeof(m_aryTempCardCount));
zeromemory(&m_PrivateRoomInfo, sizeof(CMD_GF_Private_Room_Info));
initNet();
initScene();
return true;
}
//进场动画完成回调;
void DZGameScene::onEnterTransitionDidFinish()
{
GameFrameBase::onEnterTransitionDidFinish();
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
// 录像模式;
if (m_IsGameRecord)
{
pAudio->stopBackgroundMusic(true);
StartRecord(DZ_GAME_PLAYER);
}
else
{
if (true == GAME_MUISCBG)
{
pAudio->playBackgroundMusic("Games/DaZha/Sound/backmusic.mp3", true);
}
// 暂时停了测试;
#if CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM
pAudio->stopBackgroundMusic(true);
#endif
// 增加游戏内事件处理;
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addCustomEventListener(SHOW_PRIVATE_END, CC_CALLBACK_1(DZGameScene::onEventShowPrivate, this));
CGameServerItem* pGameServerItem = GameMission::g_pGameServerItem;
CC_ASSERT(pGameServerItem != nullptr);
if (pGameServerItem != nullptr)
{
m_kGameMission.SetServerItem(pGameServerItem);
m_kGameMission.start();
}
}
}
//场景退出;
void DZGameScene::onExit()
{
GameFrameBase::onExit();
for (int i = 0; i < DZ_GAME_PLAYER; i++)
{
SafeDelete(m_aryPlayer[i]);
}
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->removeCustomEventListeners(SHOW_PRIVATE_END);
}
//场景初始化;
void DZGameScene::initScene()
{
//根节点;
m_rootNode = CSLoader::createNodeWithVisibleSize("Games/DaZha/GameScene.csb");
CC_ASSERT(m_rootNode != nullptr);
this->addChild(m_rootNode, ZO_DEFAULT);
// 公告;
auto ImageSytem = (ImageView*)m_rootNode->getChildByName("ImgRoll");
ASSERT(ImageSytem!=nullptr);
SetSystemNode(ImageSytem);
//桌子节点;
auto tablePanel = static_cast<Sprite*>(m_rootNode->getChildByName("panelTable"));
CC_ASSERT(tablePanel != nullptr);
for (int i = 0; i < DZ_GAME_PLAYER; i++)
{
const char* lpcStr = __String::createWithFormat("panelChair_%d", i)->getCString();
Layout* layout = static_cast<Layout*>(m_rootNode->getChildByName(lpcStr));
CC_ASSERT(layout!=nullptr);
m_aryPlayer[i] = new DZ_GamePlayer(i, layout);
// 自己不可点击;
// if (i != DZ_SELF_VIEW_ID)
{
layout->addClickEventListener([i, this](Ref* pSender){
CC_ASSERT(pSender != nullptr);
if (nullptr == pSender) return;
if ((m_aryPlayer[i] != nullptr) && m_aryPlayer[i]->getUserItem(false) != nullptr)
{
PlayerScene* playerScene = PlayerScene::create();
playerScene->showPlayerInfo(m_aryPlayer[i]);
this->addChild(playerScene, ZO_TRUSTEE);
}
});
}
}
m_pLocalPlayer = m_aryPlayer[DZ_SELF_VIEW_ID];
auto exitCallFunc = [=](Ref*){
auto callback = [=](){
onClickExitGameButton(nullptr);
this->runAction(Sequence::createWithTwoActions(DelayTime::create(0.2f), CallFunc::create([=]{
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME);
})));
};
PopScene::Instance().show(utility::a_u8("您确定要退出游戏吗?"), callback, nullptr);
};
//退出按钮;
m_pBtnLeave = static_cast<Button*>(tablePanel->getChildByName("btnExit"));
CC_ASSERT(m_pBtnLeave != nullptr);
m_pBtnLeave->addClickEventListener(exitCallFunc);
// 离开按钮;
m_btnDismissRoom = (Button*)tablePanel->getChildByName("btnDismiss");
CC_ASSERT(m_btnDismissRoom != nullptr);
m_btnDismissRoom->setVisible(false);
m_btnDismissRoom->addClickEventListener([=](Ref *pSender){
std::string strTip;
if (0 == m_PrivateRoomInfo.dwPlayCout && false == m_PrivateRoomInfo.bStartGame)
{
strTip = "您确定要解散房间吗?";
}
else
{
strTip = "您确定要解散房间吗?";
}
// 解散房间函数;
auto callback = [this](){
onEventAgreeDismissRoom(true);
};
PopScene::Instance().show(utility::a_u8(strTip.c_str()), callback, nullptr);
});
//设置按钮
auto btnSetting = static_cast<Button*>(tablePanel->getChildByName("btnSetting"));
CC_ASSERT(btnSetting != nullptr);
btnSetting->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
TipNode* pNode = SetScene::create();
CC_ASSERT(pNode != nullptr);
this->addChild(pNode, ZO_ANI);
pNode->pushScene();
});
//聊天按钮;
m_btnChat = static_cast<Button*>(tablePanel->getChildByName("btnChat"));
CC_ASSERT(m_btnChat != nullptr);
m_btnChat->setVisible(false);
m_btnChat->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
auto chatLayer = ChatLayer::create(m_vecShortChatList);
CC_ASSERT(chatLayer != nullptr);
this->addChild(chatLayer, ZO_ANI);
chatLayer->pushScene();
// 7777666543和JJQJ1099885
//BYTE cbLastCard[10] = { 0x37, 0x37, 0x17, 0x07, 0x36, 0x16, 0x06, 0x35, 0x24, 0x13 };
//BYTE cbNowCard[10] = { 0x4f, 0x4e, 0x2c, 0x1b, 0x0a, 0x29, 0x19, 0x28, 0x28, 0x05 };
//BYTE cbLastCard[10] = { 0x38, 0x18, 0x35, 0x15, 0x05, 0x34, 0x24, 0x14, 0x14, 0x13 };
//BYTE cbNowCard[10] = { 0x4e, 0x3a, 0x2a, 0x1a, 0x19, 0x19, 0x09, 0x27, 0x17, 0x07 };
//BYTE cbLastCard[10] = { 0x26, 0x16, 0x06, 0x33, 0x33, 0x13, 0x35, 0x25, 0x4f, 0x14 };
//BYTE cbNowCard[10] = { 0x3c, 0x2c, 0x2c, 0x3b, 0x2b, 0x1b, 0x15, 0x05, 0x24, 0x04 };
//BYTE cbLastCard[10] = { 0x32, 0x12, 0x02, 0x21, 0x21, 0x11, 0x3d, 0x2d, 0x0d, 0x28 };
//DZ_CMD_C_OutCard LastOutCard;
//zeromemory(&LastOutCard, sizeof(LastOutCard));
//LastOutCard.isLastCard = false;
//LastOutCard.cbCardCount = 10;
//CopyMemory(LastOutCard.cbCardData, cbLastCard, countarray(cbLastCard));
//m_GameLogic.SortCardList(LastOutCard.cbCardData, LastOutCard.cbCardCount, DZ_ST_ORDER);
//LastOutCard.cbCardType = m_GameLogic.GetCardType(LastOutCard.cbCardData, LastOutCard.cbCardCount, LastOutCard.isLastCard);
//if (LastOutCard.cbCardType == DZ_CT_ERROR)
//{
// ASSERT(FALSE);
//}
//DZ_CMD_C_OutCard NowOutCard;
//zeromemory(&NowOutCard, sizeof(NowOutCard));
//NowOutCard.isLastCard = false;
//NowOutCard.cbCardCount = 10;
//CopyMemory(NowOutCard.cbCardData, cbNowCard, countarray(cbLastCard));
////NowOutCard.cbCardType = DZ_CT_THREE_LINE;
//// 排序;
//m_GameLogic.SortCardList(NowOutCard.cbCardData, NowOutCard.cbCardCount, DZ_ST_ORDER);
//NowOutCard.cbCardType = m_GameLogic.GetCardType(NowOutCard.cbCardData, NowOutCard.cbCardCount, NowOutCard.isLastCard);
////类型判断
//int bCardType = m_GameLogic.GetCardType(NowOutCard.cbCardData, NowOutCard.cbCardCount, NowOutCard.isLastCard);
//if ((bCardType&NowOutCard.cbCardType) == DZ_CT_ERROR)
//{
// ASSERT(FALSE);
//}
////更随出牌
//if (LastOutCard.cbCardCount > 0 && m_GameLogic.CompareCard(&LastOutCard, &NowOutCard) == false)
//{
// ASSERT(FALSE);
//}
});
//语音按钮;
m_btnVoice = (Button*)tablePanel->getChildByName("btnVoice");
CC_ASSERT(m_btnVoice != nullptr);
m_btnVoice->setVisible(false);
m_btnVoice->addTouchEventListener(CC_CALLBACK_2(DZGameScene::OnButtonVoiceTouched, this));
m_pBtnTrustee = static_cast<Button*>(tablePanel->getChildByName("btnTrust"));
CC_ASSERT(m_pBtnTrustee != nullptr);
m_pBtnTrustee->addClickEventListener([=](Ref*){
if (!m_bGameStart) return;
DZ_CMD_C_Trustee mData;
mData.bTrustee = !m_aryTrustee[DZ_SELF_VIEW_ID];
SendSocketData(DZ_SUB_C_TRUSTEE, &mData, sizeof(DZ_CMD_C_Trustee));
});
m_pBtnTrustee->setVisible(false);
// 排序;
m_pBtnSort = static_cast<Button*>(tablePanel->getChildByName("btnSort"));
CC_ASSERT(m_pBtnSort != nullptr);
m_pBtnSort->addClickEventListener([=](Ref*){
if (!m_bGameStart) return;
if (m_aryHandCardCount[DZ_SELF_VIEW_ID] <= 0) return;
if (m_nSort == DZ_ST_ORDER)
{
m_nSort = DZ_ST_COUNT;
}
else
{
m_nSort = DZ_ST_ORDER;
}
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
});
m_pBtnSort->setVisible(false);
//叫牌面板;
m_pPanelCallCard = static_cast<Layout*>(m_rootNode->getChildByName("panelCallCard"));
CC_ASSERT(m_pPanelCallCard != nullptr);
m_pPanelCallCard->setVisible(false);
//叫牌手牌面板;
m_pPanelCallHandCard = static_cast<Layout*>(m_pPanelCallCard->getChildByName("panelCallHandCard"));
CC_ASSERT(m_pPanelCallHandCard != nullptr);
m_pCallCardLayer = DZHandCardLayer::create(m_pPanelCallHandCard->getContentSize(), [=](uint8*, uint8){
uint8 aryCardData[DZ_MAX_COUNT] = {0};
uint8 cbCardCount = 0;
m_pCallCardLayer->getShootCardData(aryCardData, cbCardCount);
bool bShow = cbCardCount == 1;
m_pBtnCallCard->setEnabled(bShow);
}, DZ_CARD_SPRITE_CALL);
m_pPanelCallHandCard->addChild(m_pCallCardLayer);
m_pCallCardLayer->setMultiSelect(false);
//叫牌按钮;
m_pBtnCallCard = static_cast<Button*>(m_pPanelCallCard->getChildByName("btnCallCard"));
CC_ASSERT(m_pBtnCallCard != nullptr);
m_pBtnCallCard->setVisible(false);
m_pBtnCallCard->addClickEventListener([=](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
//uint8 aryCardData[DZ_MAX_COUNT] = { 0 };
//uint8 cbCardCount = 0;
//m_pCallCardLayer->getShootCardData(aryCardData, cbCardCount);
//if (cbCardCount > 0)
//{
// DZ_CMD_C_CallCard askForCard;
// askForCard.cbCardData = aryCardData[0];
// SendSocketData(DZ_SUB_C_CALL_CARD, &askForCard, sizeof(CMD_C_AskForCard));
// m_pBtnCallCard->setEnabled(false);
//}
});
//要完牌面板;
m_pPanelCallFinished = static_cast<Layout*>(m_rootNode->getChildByName("panelCallFinished"));
CC_ASSERT(m_pPanelCallFinished != nullptr);
m_pPanelCallFinished->setVisible(false);
//提示面板;
m_pPanelTips = static_cast<Layout*>(m_rootNode->getChildByName("panelTips"));
CC_ASSERT(m_pPanelTips != nullptr);
m_pPanelTips->setVisible(false);
//提示文字;
m_txtTip = static_cast<Text*>(m_pPanelTips->getChildByName("txtTip"));
CC_ASSERT(m_txtTip != nullptr);
//准备按钮;
m_pBtnReady = static_cast<Button*>(m_rootNode->getChildByName("btnReady"));
CC_ASSERT(m_pBtnReady != nullptr);
m_pBtnReady->addClickEventListener([=](Ref*){
YSAudioEngine::getInstance()->playBtnClickEffect();
SendUserReady();
});
//叫分按钮面板;
auto panelCallScore = static_cast<Layout*>(m_rootNode->getChildByName("panelCallScore"));
CC_ASSERT(panelCallScore != nullptr);
m_pBtnCallScore = static_cast<Button*>(panelCallScore->getChildByName("btnCallScore"));
CC_ASSERT(m_pBtnCallScore != nullptr);
m_pBtnCallScore->addClickEventListener([=](Ref*){
YSAudioEngine::getInstance()->playBtnClickEffect();
PopScene::Instance().show(utility::a_u8("你确定要打独吗?"), [=](){
DZ_CMD_C_CallScore call;
call.cbCallScore = 1;
SendSocketData(DZ_SUB_C_CALL_SCORE, &call, sizeof(DZ_CMD_C_CallScore));
}, nullptr);
});
//不叫按钮;
m_pBtnPassCall = static_cast<Button*>(panelCallScore->getChildByName("btnPassCall"));
CC_ASSERT(m_pBtnPassCall != nullptr);
m_pBtnPassCall->addClickEventListener([=](Ref*){
SendPassCall();
});
//出牌按钮面板;
auto panelOutCard = static_cast<Layout*>(m_rootNode->getChildByName("panelOutCard"));
CC_ASSERT(panelOutCard != nullptr);
//不出按钮;
m_pBtnPass = static_cast<Button*>(panelOutCard->getChildByName("btnPass"));
CC_ASSERT(m_pBtnPass != nullptr);
m_pBtnPass->addClickEventListener([this](Ref*){
if (getSelfChairID() == m_wCurChairID)
{
SendSocketData(DZ_SUB_C_PASS_CARD);
m_pHandCardLayer->downAllCard();
}
});
//提示按钮;
m_pBtnTips = static_cast<Button*>(panelOutCard->getChildByName("btnTips"));
CC_ASSERT(m_pBtnTips != nullptr);
m_pBtnTips->addClickEventListener(CC_CALLBACK_1(DZGameScene::onButtonTipClick, this));
//出牌按钮;
m_pBtnOutCard = static_cast<Button*>(panelOutCard->getChildByName("btnOutCard"));
CC_ASSERT(m_pBtnOutCard != nullptr);
m_pBtnOutCard->addClickEventListener([this](Ref*){
//播放出牌音效;
playSoundEffect(DZ_ST_OUT_CARD);
// 重置出牌信息;
zeromemory(&m_SelfOutCard, sizeof(DZ_CMD_C_OutCard));
m_pHandCardLayer->getShootCardData(m_SelfOutCard.cbCardData, m_SelfOutCard.cbCardCount);
// 牌型检测前必须排序;
m_GameLogic.SortCardList(m_SelfOutCard.cbCardData, m_SelfOutCard.cbCardCount, DZ_ST_ORDER);
ASSERT(m_pHandCardLayer->getHandCardCount() >= m_SelfOutCard.cbCardCount);
m_SelfOutCard.isLastCard = (m_pHandCardLayer->getHandCardCount() == m_SelfOutCard.cbCardCount);
m_SelfOutCard.cbCardType = m_GameLogic.GetCardType(m_SelfOutCard.cbCardData, m_SelfOutCard.cbCardCount, m_SelfOutCard.isLastCard);
auto callback = [=](){
uint16 wHeadSize = sizeof(DZ_CMD_C_OutCard) - sizeof(m_SelfOutCard.cbCardData);
uint16 wSendSize = wHeadSize + sizeof(uint8)*m_SelfOutCard.cbCardCount;
SendSocketData(DZ_SUB_C_OUT_CARD, &m_SelfOutCard, wSendSize);
};
if (m_bNobodyCall && (m_wFriendChairID == m_wTurnWiner) && m_GameLogic.IsBombType(m_SelfOutCard.cbCardType))
{
PopScene::Instance().show(utility::a_u8("你确定要打你伙伴的牌吗?"), callback, [=](){
if (getSelfChairID() == m_wCurChairID)
{
SendSocketData(DZ_SUB_C_PASS_CARD);
m_pHandCardLayer->downAllCard();
}
});
}
else
{
callback();
}
});
//更多出牌按钮面板;
m_pPanleMoveOutCard = static_cast<Layout*>(m_rootNode->getChildByName("panelMoveOutCard"));
CC_ASSERT(m_pPanleMoveOutCard != nullptr);
m_pPanleMoveOutCard->setVisible(false);
for (BYTE i = 0; i < MOVE_BTN_OUT_CARD_COUNT; i++)
{
std::string strKey = StringUtils::format("btnOutCard_%d", g_MoveBtnOutCards[i]);
auto btnOutCard = static_cast<Button*>(m_pPanleMoveOutCard->getChildByName(strKey));
CC_ASSERT(btnOutCard != nullptr);
btnOutCard->addClickEventListener([this](Ref* ref){
//播放出牌音效;
playSoundEffect(DZ_ST_OUT_CARD);
Button* btn = static_cast<Button*>(ref);
if (btn == nullptr) return;
auto pData = (ComExtensionData*)btn->getComponent("ComExtensionData");
std::string strUserData = pData->getCustomProperty();
int iCardType = atoi(strUserData.c_str());
if (iCardType > DZ_CT_ERROR && iCardType < DZ_CT_COUNT)
{
// 重置出牌信息;
zeromemory(&m_SelfOutCard, sizeof(DZ_CMD_C_OutCard));
m_pHandCardLayer->getShootCardData(m_SelfOutCard.cbCardData, m_SelfOutCard.cbCardCount);
ASSERT(m_pHandCardLayer->getHandCardCount() >= m_SelfOutCard.cbCardCount);
m_SelfOutCard.isLastCard = (m_pHandCardLayer->getHandCardCount() == m_SelfOutCard.cbCardCount);
m_SelfOutCard.cbCardType = m_GameLogic.TransListToInt(0, iCardType);
auto callback = [=](){
uint16 wHeadSize = sizeof(DZ_CMD_C_OutCard) - sizeof(m_SelfOutCard.cbCardData);
uint16 wSendSize = wHeadSize + sizeof(uint8)*m_SelfOutCard.cbCardCount;
SendSocketData(DZ_SUB_C_OUT_CARD, &m_SelfOutCard, wSendSize);
};
if (m_bNobodyCall && (m_wFriendChairID == m_wTurnWiner) && m_GameLogic.IsBombType(m_SelfOutCard.cbCardType))
{
PopScene::Instance().show(utility::a_u8("你确定要打你伙伴的牌吗?"), callback, nullptr);
}
else
{
callback();
}
}
});
}
//提示面板;
m_pPanelTrustee = static_cast<Layout*>(m_rootNode->getChildByName("panelTrustee"));
CC_ASSERT(m_pPanelTrustee != nullptr);
//取消托管按钮;
m_pbtnCancelTrustee = static_cast<Button*>(m_pPanelTrustee->getChildByName("btnTrustee"));
CC_ASSERT(m_pbtnCancelTrustee != nullptr);
m_pbtnCancelTrustee->addClickEventListener([=](Ref*){
if (!m_bGameStart || !m_aryTrustee[DZ_SELF_VIEW_ID]) return;
DZ_CMD_C_Trustee mData;
mData.bTrustee = false;
SendSocketData(DZ_SUB_C_TRUSTEE, &mData, sizeof(DZ_CMD_C_Trustee));
});
//提示文字;
m_pSprTips = static_cast<Sprite*>(m_rootNode->getChildByName("sprTips"));
CC_ASSERT(m_pSprTips != nullptr);
//手牌节点;
auto panelHandCard = static_cast<Layout*>(m_rootNode->getChildByName("panelHandCard"));
auto func = CC_CALLBACK_2(DZGameScene::selectCardCallback, this);
m_pHandCardLayer = DZHandCardLayer::create(panelHandCard->getContentSize(), func);
panelHandCard->addChild(m_pHandCardLayer);
//加载扑克牌缓存;
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Table/PinCard.plist");
//房间号背景;
auto imgRoomID = m_rootNode->getChildByName("imgRoomID");
CC_ASSERT(imgRoomID != nullptr);
////房间号标题;
//m_txtRoomIDTip = static_cast<Text*>(imgRoomID->getChildByName("txtDesc"));
//CC_ASSERT(m_txtRoomIDTip != nullptr);
//m_txtRoomIDTip->setVisible(false);
//房间号;
m_txtPrivateRoomID = static_cast<Text*>(imgRoomID->getChildByName("txtPrivateRoomID"));
CC_ASSERT(m_txtPrivateRoomID != nullptr);
m_txtPrivateRoomID->setVisible(false);
////规则背景;
//m_imgRule = (ImageView*)m_rootNode->getChildByName("imgRule");
//CC_ASSERT(m_imgRule != nullptr);
//m_imgRule->setVisible(false);
//局数;
m_txtPrivatePlayCount = static_cast<Text*>(imgRoomID->getChildByName("txtPrivatePlayCount"));
CC_ASSERT(m_txtPrivatePlayCount != nullptr);
////规则背景;
//m_imgGameRule = (ImageView*)m_rootNode->getChildByName("imgGameRule");
//CC_ASSERT(m_imgGameRule != nullptr);
//m_imgGameRule->setVisible(false);
//游戏规则;
m_txtGameRule1 = static_cast<Text*>(imgRoomID->getChildByName("txtGameRule1"));
CC_ASSERT(m_txtGameRule1 != nullptr);
m_txtGameRule1->setString("");
//游戏规则;
m_txtGameRule2 = static_cast<Text*>(imgRoomID->getChildByName("txtGameRule2"));
CC_ASSERT(m_txtGameRule2 != nullptr);
m_txtGameRule2->setString("");
//游戏规则;
m_txtGameRule3 = static_cast<Text*>(imgRoomID->getChildByName("txtGameRule3"));
CC_ASSERT(m_txtGameRule3 != nullptr);
m_txtGameRule3->setString("");
//微信分享按钮;
m_btnWeiXin = (Button*)m_rootNode->getChildByName("btnWeiXin");
CC_ASSERT(m_btnWeiXin != nullptr);
m_btnWeiXin->setVisible(false);
// 分享房间号;
m_btnWeiXin->addClickEventListener([=](Ref*){
//// 统计在线人数;
//uint8 cbPlayerCount = 0;
//for (int i = 0; i < DZ_GAME_PLAYER; i++)
//{
// GamePlayer* pPlayer = m_aryPlayer[i];
// if (pPlayer != nullptr && pPlayer->getUserItem(false) != nullptr)
// {
// cbPlayerCount++;
// }
//}
//std::string strJoker = "带王";
//// 不带王规则;
//if ((m_PrivateRoomInfo.bGameRuleIdex&eDZRuleEnum_NO_JOKER) > 0)
//{
// strJoker = "不带王";
//}
//std::string strTitle = StringUtils::format("打炸~%s", strJoker.c_str());
std::string strGameRule = getGameRule(m_PrivateRoomInfo.bGameRuleIdex);
std::string strText = StringUtils::format("房间号:[%u], %d 局, %s。", m_PrivateRoomInfo.dwRoomNum,
m_PrivateRoomInfo.dwPlayTotal, strGameRule.c_str());
std::string strUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_URL);
std::string strUrlInfo = StringUtils::format("%s?param=%d", strUrl.c_str(), m_PrivateRoomInfo.dwRoomNum);
MissionWeiXin::Instance().shareUrlWeiXin(strUrlInfo, "万年打炸", strText);
//SelectShareScene::Instance().shareRoomInfo(strUrlInfo, utility::a_u8("打炸"), strText, 0);
});
// 语音标志;
m_pVoiceNode = (Node*)m_rootNode->getChildByName("VoiceNode");
CC_ASSERT(m_pVoiceNode != nullptr);
m_pVoiceNode->setVisible(false);
m_imgGameEndAni = (Sprite*)m_rootNode->getChildByName("imgGameEndAni");
CC_ASSERT(m_imgGameEndAni != nullptr);
m_imgGameEndAni->setVisible(false);
// 结算面板;
m_pResultLayer = DZGameEndNode::create();
m_pResultLayer->setVisible(false);
this->addChild(m_pResultLayer, ZO_END);
// 私人场面板;
m_pPrivateScene = DZPrivateEndNode::create();
m_pPrivateScene->setVisible(false);
this->addChild(m_pPrivateScene, ZO_PRIVATE);
//对手机返回键的监听 ;
auto keyListener = EventListenerKeyboard::create();
//和回调函数绑定 ;
keyListener->onKeyReleased = [=](EventKeyboard::KeyCode keyCode, Event * pEvent){
//返回值处理;
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
{
exitCallFunc(nullptr);
}
};
//添加到事件分发器中;
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
loadShortChat("Games/DaZha/ShortChat/ChatInfo.json");
//重置场景;
resetScene();
//重置数据;
ResetAllData();
}
//重置场景;
void DZGameScene::resetScene(bool bAll/* = false*/)
{
//重置玩家UI;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
m_aryPlayer[i]->resetUI(bAll);
}
//m_pNodeFriendCard->removeAllChildren();
//隐藏所有按钮;
m_pBtnCallCard->setVisible(false);
m_pBtnCallScore->setVisible(false);
m_pBtnPassCall->setVisible(false);
m_pBtnPass->setVisible(false);
m_pBtnTips->setVisible(false);
m_pBtnOutCard->setVisible(false);
m_pPanleMoveOutCard->setVisible(false);
m_pBtnReady->setVisible(false);
//隐藏面板;
m_pPanelTips->setVisible(false);
m_pSprTips->setVisible(false);
m_pPanelTrustee->setVisible(false);
m_pPanelCallCard->setVisible(false);
//清空手牌;
m_pHandCardLayer->setLordMode(false);
m_pHandCardLayer->initUIData();
}
//重置数据
void DZGameScene::resetData()
{
m_bGameStart = false;
m_bNobodyCall = false;
m_wLandChairID = INVALID_CHAIR;
m_wCurChairID = INVALID_CHAIR;
m_wFriendChairID = INVALID_CHAIR;
m_cbLastOutCardType = DZ_CT_ERROR;
m_wTurnWiner = INVALID_CHAIR;
//m_cbTurnCardCount = 0;
m_cbSearchOutCardIndex = 0;
m_cbBombCount = 0;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
m_aryTrustee[i] = false;
}
zeromemory(m_aryTempCardCount, sizeof(m_aryTempCardCount));
//zeromemory(m_cbTurnCardData, sizeof(m_cbTurnCardData));
zeromemory(&m_TurnOutCard, sizeof(m_TurnOutCard));
zeromemory(&m_TipOutCard, sizeof(m_TipOutCard));
zeromemory(m_aryHandCardData, sizeof(m_aryHandCardData));
zeromemory(m_aryHandCardCount, sizeof(m_aryHandCardCount));
zeromemory(m_aryAllHandCardData, sizeof(m_aryAllHandCardData));
m_pBtnSort->setVisible(false);
}
//重置数据(相当于玩家离开);
void DZGameScene::ResetAllData()
{
resetScene();
resetData();
}
//重置桌子;
void DZGameScene::ResetTable()
{
resetScene(true);
resetData();
}
//获取快捷语音文件路径;
const std::string DZGameScene::getShortChatSoundPath(uint8 cbGender, int nIndex)
{
// 短语;
std::string strFilePath = "Games/DaZha/ShortChat/";
if (cbGender == enMan)
{
strFilePath += StringUtils::format("man/%d.mp3", nIndex);
}
else
{
strFilePath += StringUtils::format("woman/%d.mp3", nIndex);
}
return strFilePath;
}
//绑定网络消息;
void DZGameScene::initNet()
{
addNetCBDefine(DZ_SUB_S_GAME_START, this, DZGameScene::onSubGameStart);
addNetCBDefine(DZ_SUB_S_CALL_SCORE, this, DZGameScene::onSubCallScore);
addNetCBDefine(DZ_SUB_S_BANKER_INFO, this, DZGameScene::onSubBankerInfo);
addNetCBDefine(DZ_SUB_S_OUT_CARD, this, DZGameScene::onSubOutCard);
addNetCBDefine(DZ_SUB_S_PASS_CARD, this, DZGameScene::onSubPassCard);
addNetCBDefine(DZ_SUB_S_GAME_END, this, DZGameScene::onSubGameEnd);
addNetCBDefine(DZ_SUB_S_TRUSTEE, this, DZGameScene::onSubTrustee);
addNetCBDefine(DZ_SUB_S_RANKING, this, DZGameScene::onSubRanking);
}
//按钮点击事件;
void DZGameScene::onButtonTipClick(Ref*)
{
if (getSelfChairID() != m_wCurChairID)
{
return;
}
//搜索出牌;
tagDZSearchCardResult mCardResult;
uint8 cbResultCount = m_GameLogic.SearchOutCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], &m_TurnOutCard, &mCardResult);
if (cbResultCount > 0)
{
if (m_cbSearchOutCardIndex>=cbResultCount)
{
m_cbSearchOutCardIndex = 0;
}
//弹起牌;
m_pHandCardLayer->shootCardData(mCardResult.cbResultCard[m_cbSearchOutCardIndex], mCardResult.cbCardCount[m_cbSearchOutCardIndex]);
m_pBtnOutCard->setEnabled(true);
m_cbSearchOutCardIndex++;
}
}
bool DZGameScene::OnEventSceneMessage(uint8 cbGameStatus, bool bLookonUser, void* pData, int nDataSize)
{
switch (cbGameStatus)
{
case DZ_GAME_SCENE_FREE:
{
return onGameSceneFree(pData, nDataSize);
}
case DZ_GAME_SCENE_SEND:
{
return onGameSceneSendCard(pData, nDataSize);
}
case DZ_GAME_SCENE_CALL_SCORE:
{
return onGameSceneCallScore(pData, nDataSize);
}
case DZ_GAME_SCENE_PLAY:
{
return onGameScenePlay(pData, nDataSize);
}
default:
break;
}
return true;
}
//恢复空闭场景;
bool DZGameScene::onGameSceneFree(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(DZ_CMD_S_StatusFree));
DZ_CMD_S_StatusFree* pStatusFree = (DZ_CMD_S_StatusFree*)pData;
m_nCellScore = pStatusFree->lCellScore;
m_pBtnReady->setVisible(true);
return true;
}
//恢复发牌场景;
bool DZGameScene::onGameSceneSendCard(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(DZ_CMD_S_StatusSendCard));
DZ_CMD_S_StatusSendCard* pStatusSend = (DZ_CMD_S_StatusSendCard*)pData;
m_bGameStart = true;
m_nCellScore = pStatusSend->lCellScore;
//拷贝手牌;
memcpy(m_aryHandCardData, pStatusSend->cbHandCardData, sizeof(pStatusSend->cbHandCardData));
//初始化牌数;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
uint16 wViewID = SwitchViewChairID(i);
uint8 cbCardCount = pStatusSend->cbHandCardCount[i];
m_aryHandCardCount[wViewID] = cbCardCount;
m_aryTrustee[wViewID] = pStatusSend->bUserTrustee[i];
m_aryPlayer[wViewID]->setHandCardCount(cbCardCount, !m_IsGameRecord);
m_aryPlayer[wViewID]->setTrustVisible(m_aryTrustee[wViewID]);
}
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
m_pBtnSort->setVisible(true); // 显示牌型按钮;
m_wCurChairID = pStatusSend->wCurrentUser;
return true;
}
//恢复叫分场景;
bool DZGameScene::onGameSceneCallScore(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(DZ_CMD_S_StatusCallScore));
DZ_CMD_S_StatusCallScore* pStatusCall = (DZ_CMD_S_StatusCallScore*)pData;
m_bGameStart = true;
m_nCellScore = pStatusCall->lCellScore;
//拷贝手牌;
memcpy(m_aryHandCardData, pStatusCall->cbHandCardData, sizeof(pStatusCall->cbHandCardData));
//初始化牌数;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
uint16 wViewID = SwitchViewChairID(i);
uint8 cbCardCount = pStatusCall->cbHandCardCount[i];
m_aryHandCardCount[wViewID] = cbCardCount;
m_aryTrustee[wViewID] = pStatusCall->bUserTrustee[i];
m_aryPlayer[wViewID]->setHandCardCount(cbCardCount, !m_IsGameRecord);
if (pStatusCall->cbScoreInfo[i] > 0)
{
m_aryPlayer[wViewID]->setCallVisible(true, pStatusCall->cbScoreInfo[i]);
}
m_aryPlayer[wViewID]->setTrustVisible(m_aryTrustee[wViewID]);
}
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
m_pBtnSort->setVisible(true); // 显示牌型按钮;
//更新出牌按钮;
updateCallButtons(pStatusCall->wCurrentUser, 255);
m_wCurChairID = pStatusCall->wCurrentUser;
return true;
}
//恢复游戏场景;
bool DZGameScene::onGameScenePlay(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(DZ_CMD_S_StatusPlay));
DZ_CMD_S_StatusPlay* pStatusPlay = (DZ_CMD_S_StatusPlay*)pData;
m_bGameStart = true;
m_bNobodyCall = pStatusPlay->bCallCard;
m_wTurnWiner = pStatusPlay->wTurnWiner;
m_TurnOutCard.cbCardCount = pStatusPlay->cbTurnCardCount;
m_TurnOutCard.cbCardType = pStatusPlay->cbTurnCardType;
m_TurnOutCard.isLastCard = pStatusPlay->isLastCard;
memcpy(m_TurnOutCard.cbCardData, pStatusPlay->cbTurnCardData, pStatusPlay->cbTurnCardCount);
m_wLandChairID = pStatusPlay->wBankerUser;
m_wCurChairID = pStatusPlay->wCurrentUser;
m_wFriendChairID = pStatusPlay->wFriendChairID;
if (m_bNobodyCall)
{
if (pStatusPlay->wFriendChairID != INVALID_CHAIR)
{
uint16 wFriendViewID = SwitchViewChairID(pStatusPlay->wFriendChairID);
m_aryPlayer[wFriendViewID]->setLand(1);
}
}
else
{
//设置地主标志;
uint16 wLandChairID = SwitchViewChairID(m_wLandChairID);
m_aryPlayer[wLandChairID]->setLand(2);
}
//初始化牌数;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
uint16 wViewID = SwitchViewChairID(i);
m_aryTrustee[wViewID] = pStatusPlay->bTrustee[i];
uint8 cbCardCount = pStatusPlay->cbHandCardCount[i];
m_aryHandCardCount[wViewID] = cbCardCount;
m_aryPlayer[wViewID]->setHandCardCount(cbCardCount, !m_IsGameRecord);
//最后出牌玩家视图;
if (i == m_wTurnWiner)
{
uint8 cbCardData[DZ_MAX_COUNT] = { 0 };
CopyMemory(cbCardData, pStatusPlay->cbTurnCardData, pStatusPlay->cbTurnCardCount);
m_GameLogic.SortCardList(cbCardData, pStatusPlay->cbTurnCardCount, DZ_ST_COUNT);
m_aryPlayer[wViewID]->setOutCardData(cbCardData, pStatusPlay->cbTurnCardCount);
}
if (DZ_SELF_VIEW_ID == wViewID)
{
//拷贝手牌;
memcpy(m_aryHandCardData, pStatusPlay->cbHandCardData, cbCardCount);
m_GameLogic.SortCardList(m_aryHandCardData, cbCardCount, m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, cbCardCount);
m_pBtnSort->setVisible(true); // 显示牌型按钮;
}
m_aryPlayer[wViewID]->setTrustVisible(m_aryTrustee[wViewID]);
}
// 排名;
for (BYTE i = 0; i < pStatusPlay->wWinCount; i++)
{
uint16 wViewID = SwitchViewChairID(pStatusPlay->wWinOrder[i]);
if (wViewID != INVALID_CHAIR && m_aryPlayer[wViewID])
{
m_aryPlayer[wViewID]->showRanking(i+1);
}
}
//更新按钮状态;
updateButtonsStatus(pStatusPlay->wCurrentUser, m_cbTimeOutCard, (0 == pStatusPlay->cbTurnCardCount));
return true;
}
void DZGameScene::onSubGameStart(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_GameStart));
DZ_CMD_S_GameStart* pGameStart = (DZ_CMD_S_GameStart*)pBuffer;
m_txtTip->setString("");
m_bGameStart = true;
BYTE cbFullCount = 0;
//清楚准备状态;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
m_aryPlayer[i]->setReadyVisible(false);
WORD wViewID = SwitchViewChairID(i);
m_aryTempCardCount[wViewID] = pGameStart->cbCardCount[i];
cbFullCount += m_aryTempCardCount[wViewID];
}
m_wCurChairID = pGameStart->wCurrentUser;
//拷贝手牌;
memcpy(m_aryHandCardData, pGameStart->cbCardData, sizeof(pGameStart->cbCardData));
if (m_IsGameRecord)
{
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
WORD wViewID = SwitchViewChairID(i);
m_aryHandCardCount[wViewID] = pGameStart->cbCardCount[i];
m_aryPlayer[wViewID]->setHandCardCount(m_aryHandCardCount[wViewID], !m_IsGameRecord);
}
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
////更新叫分按钮;
//updateCallButtons(m_wCurChairID, 255);
//设置别外三家手牌;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
if (i == DZ_SELF_VIEW_ID)
{
continue;
}
m_GameLogic.SortCardList(m_aryAllHandCardData[i], m_aryHandCardCount[i], m_nSort);
bool bHorizontal = (i == DZ_TOP_VIEW_ID) ? true : false;
m_aryPlayer[i]->setHandCardData(m_aryAllHandCardData[i], m_aryHandCardCount[i], bHorizontal);
}
}
else
{
playSoundEffect(DZ_ST_DEAL_CARD);
//发牌动画;
float fDelaySendTime = 0.01f;
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
//Vec2 ptInitCard = m_rootNode->getChildByName("imgGameLogo")->getPosition();
Size sizeWin = Director::getInstance()->getWinSize();
Vec2 ptInitCard;
ptInitCard.x = sizeWin.width / 2;
ptInitCard.y = sizeWin.height / 2;
WORD wStartViewID = SwitchViewChairID(m_wCurChairID);
for (uint8 i = wStartViewID; i < (wStartViewID + cbFullCount); i++)
{
Sprite* pCardSprite = Sprite::createWithSpriteFrameName("bCardBack.png");
pCardSprite->setTag(i);
pCardSprite->setScale(0.5f);
pCardSprite->setPosition(ptInitCard);
m_rootNode->addChild(pCardSprite);
moveSendCardSprite(pCardSprite, i%DZ_GAME_PLAYER, fDelaySendTime);
fDelaySendTime = fDelaySendTime + 0.03f;
}
}
}
//玩家叫分;
void DZGameScene::onSubCallScore(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_CallScore));
DZ_CMD_S_CallScore* pCallScore = (DZ_CMD_S_CallScore*)pBuffer;
// 通知打独;
if (pCallScore->wCallScoreUser == INVALID_CHAIR && pCallScore->wCurrentUser != INVALID_CHAIR)
{
//玩家叫了3分后当前玩家为INVALID_CHAIR;
if (INVALID_CHAIR != pCallScore->wCurrentUser)
{
updateCallButtons(pCallScore->wCurrentUser, pCallScore->cbCallScore);
m_wCurChairID = pCallScore->wCurrentUser;
}
}
else
{
//转换叫分玩家视图;
uint16 wViewID = SwitchViewChairID(pCallScore->wCallScoreUser);
////播放叫分声音;
//playSoundEffect(DZ_ST_CALL, m_aryPlayer[wViewID]->GetGender(), pCallScore->cbCallScore);
//隐藏倒计时;
m_aryPlayer[wViewID]->killClock();
//不包牌的时候显示;
if (pCallScore->cbCallScore == 0xFF)
{
m_aryPlayer[wViewID]->setCallVisible(true, pCallScore->cbCallScore);
}
//如果是自已叫分隐藏叫分按钮;
if (DZ_SELF_VIEW_ID == wViewID)
{
m_pBtnCallScore->setVisible(false);
m_pBtnPassCall->setVisible(false);
}
//玩家叫了3分后当前玩家为INVALID_CHAIR;
if (INVALID_CHAIR != pCallScore->wCurrentUser)
{
updateCallButtons(pCallScore->wCurrentUser, pCallScore->cbCallScore);
m_wCurChairID = pCallScore->wCurrentUser;
}
}
}
//庄家信息;
void DZGameScene::onSubBankerInfo(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_BankerInfo));
DZ_CMD_S_BankerInfo* pBankerInfo = (DZ_CMD_S_BankerInfo*)pBuffer;
uint16 wSelfChairID = getSelfChairID();
m_wLandChairID = pBankerInfo->wBankerUser;
m_wFriendChairID = pBankerInfo->wFriendChairID[wSelfChairID];
//清除玩家叫分信息;
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
m_aryPlayer[i]->setCallVisible(false);
m_aryPlayer[i]->setLand(0);
}
m_bNobodyCall = pBankerInfo->bCallCard;
m_wCurChairID = pBankerInfo->wCurrentUser;
m_wTurnWiner = m_wCurChairID;
m_cbSearchOutCardIndex = 0;
zeromemory(&m_TurnOutCard, sizeof(m_TurnOutCard));
zeromemory(&m_TipOutCard, sizeof(m_TipOutCard));
//转换叫分玩家视图;
uint16 wBankerViewID = SwitchViewChairID(pBankerInfo->wBankerUser);
// 无打独,显示伙伴;
if (pBankerInfo->bCallCard)
{
if (pBankerInfo->wFriendChairID[wSelfChairID] != INVALID_CHAIR)
{
WORD wFriendViewID = SwitchViewChairID(pBankerInfo->wFriendChairID[wSelfChairID]);
ASSERT(wFriendViewID != INVALID_CHAIR);
if (wFriendViewID != INVALID_CHAIR)
{
m_aryPlayer[wFriendViewID]->setLand(1);
}
// 显示伙伴牌;
if (m_GameLogic.IsValidCard(pBankerInfo->cbFirendCardData))
{
if ((wSelfChairID == pBankerInfo->wBankerUser) || (wSelfChairID == pBankerInfo->wFriendChairID[pBankerInfo->wBankerUser]))
{
uint16 wFriendViewID = SwitchViewChairID(pBankerInfo->wFriendChairID[wSelfChairID]);
m_aryPlayer[wFriendViewID]->setOutCardData(&pBankerInfo->cbFirendCardData, 1, true);
}
else
{
uint16 wBankFriendViewID = SwitchViewChairID(pBankerInfo->wFriendChairID[pBankerInfo->wBankerUser]);
m_aryPlayer[wBankFriendViewID]->setOutCardData(&pBankerInfo->cbFirendCardData, 1, true);
m_aryPlayer[wBankerViewID]->setOutCardData(&pBankerInfo->cbFirendCardData, 1, true);
}
}
}
}
else
{
//设置地主标志;
m_aryPlayer[wBankerViewID]->setLand(2);
}
if (DZ_SELF_VIEW_ID == wBankerViewID)
{
updateButtonsStatus(pBankerInfo->wCurrentUser, m_cbTimeHeadOutCard, true);
}
else
{
//显示其它玩家倒计时;
m_aryPlayer[wBankerViewID]->showClock(m_cbTimeHeadOutCard);
}
}
//玩家出牌;
void DZGameScene::onSubOutCard(const void * pBuffer, uint16 wDataSize)
{
//定义变量;
DZ_CMD_S_OutCard* pOutCard = (DZ_CMD_S_OutCard*)pBuffer;
uint16 wHeadSize = sizeof(DZ_CMD_S_OutCard) - sizeof(pOutCard->cbCardData);
//效验数据;
CC_ASSERT((wDataSize >= wHeadSize) && (wDataSize == (wHeadSize + pOutCard->cbCardCount*sizeof(uint8))));
if ((wDataSize < wHeadSize) || (wDataSize != (wHeadSize + pOutCard->cbCardCount*sizeof(uint8)))) return ;
//获取出牌类型;
int cbCardType = pOutCard->cbCardType;// m_GameLogic.GetCardType(pOutCard->cbCardData, pOutCard->cbCardCount, cbStarLevel);
CC_ASSERT(pOutCard->cbCardType!= DZ_CT_ERROR);
if (pOutCard->cbCardType == DZ_CT_ERROR) return;
//转换出牌玩家视图;
uint16 wViewID = SwitchViewChairID(pOutCard->wOutCardUser);
m_aryPlayer[wViewID]->setPassVisible(false);
m_aryPlayer[wViewID]->killClock();
uint8 cbCardData[DZ_MAX_COUNT] = { 0 };
CopyMemory(cbCardData, pOutCard->cbCardData, pOutCard->cbCardCount);
m_GameLogic.SortCardList(cbCardData, pOutCard->cbCardCount, DZ_ST_COUNT);
m_aryPlayer[wViewID]->setOutCardData(cbCardData, pOutCard->cbCardCount);
m_cbLastOutCardType = pOutCard->cbCardType;
playAnimate(cbCardType, pOutCard->wOutCardUser, m_wTurnWiner);
//播放出牌声音;
uint8 cbOutCardData = pOutCard->cbCardData[pOutCard->cbCardCount - 1];
playSoundEffect(cbCardType, m_aryPlayer[wViewID]->GetGender(), cbOutCardData, true);
if (wViewID == DZ_SELF_VIEW_ID)
{
hideOutCardButtons();
m_GameLogic.RemoveCard(pOutCard->cbCardData, pOutCard->cbCardCount, m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
m_aryHandCardCount[DZ_SELF_VIEW_ID] -= pOutCard->cbCardCount;
//剩余牌数大于1再排序;
if (m_aryHandCardCount[DZ_SELF_VIEW_ID]>1)
{
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
}
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
}
else
{
m_aryHandCardCount[wViewID] -= pOutCard->cbCardCount;
if (m_IsGameRecord)
{
m_GameLogic.RemoveCard(pOutCard->cbCardData, pOutCard->cbCardCount, m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID] + pOutCard->cbCardCount);
m_GameLogic.SortCardList(m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID], m_nSort);
bool bHorizontal = (wViewID == DZ_TOP_VIEW_ID)?true:false;
m_aryPlayer[wViewID]->setHandCardData(m_aryAllHandCardData[wViewID], m_aryHandCardCount[wViewID], bHorizontal);
}
}
m_aryPlayer[wViewID]->setHandCardCount(m_aryHandCardCount[wViewID], !m_IsGameRecord);
//此时游戏结束;
if (INVALID_CHAIR == pOutCard->wCurrentUser)
{
return;
}
m_wCurChairID = pOutCard->wCurrentUser;
m_wTurnWiner = pOutCard->wOutCardUser;
m_cbSearchOutCardIndex = 0;
//出牌类型为火箭时出牌玩家等于下个出牌玩家;
if (pOutCard->wOutCardUser == pOutCard->wCurrentUser /*|| DZ_CT_BOMB_TW == cbCardType*/)
{
zeromemory(&m_TurnOutCard, sizeof(m_TurnOutCard));
zeromemory(&m_TipOutCard, sizeof(m_TipOutCard));
}
else
{
m_TurnOutCard.cbCardCount = pOutCard->cbCardCount;
m_TurnOutCard.cbCardType = pOutCard->cbCardType;
m_TurnOutCard.isLastCard = pOutCard->isLastCard;
memcpy(m_TurnOutCard.cbCardData, pOutCard->cbCardData, sizeof(uint8)*pOutCard->cbCardCount);
}
//更新出牌按钮状态;
updateButtonsStatus(pOutCard->wCurrentUser, m_cbTimeOutCard);
//只剩一张牌时播放音效;
if (1==m_aryHandCardCount[wViewID])
{
playSoundEffect(DZ_ST_LEFT_ONE_CARD, m_aryPlayer[wViewID]->GetGender());
}
}
//玩家不出;
void DZGameScene::onSubPassCard(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_PassCard));
DZ_CMD_S_PassCard* pPassCard = (DZ_CMD_S_PassCard*)pBuffer;
//转换不出玩家视图;
uint16 wViewID = SwitchViewChairID(pPassCard->wPassCardUser);
m_aryPlayer[wViewID]->setPassVisible(true);
m_aryPlayer[wViewID]->setOutCardData(nullptr, 0);
m_aryPlayer[wViewID]->killClock();
//播放不出声音;
playSoundEffect(DZ_ST_PASS, m_aryPlayer[wViewID]->GetGender());
m_wCurChairID = pPassCard->wCurrentUser;
//如果一轮结束清空本轮出牌;
if (pPassCard->cbTurnOver)
{
m_wTurnWiner = m_wCurChairID;
m_cbSearchOutCardIndex = 0;
zeromemory(&m_TurnOutCard, sizeof(m_TurnOutCard));
zeromemory(&m_TipOutCard, sizeof(m_TipOutCard));
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
m_aryPlayer[i]->setPassVisible(false);
m_aryPlayer[i]->setOutCardData(nullptr, 0);
}
}
//如果是自已不出隐藏出牌按钮;
if (wViewID == DZ_SELF_VIEW_ID)
{
hideOutCardButtons();
}
//更新出牌按钮状态;
updateButtonsStatus(pPassCard->wCurrentUser, m_cbTimeOutCard, pPassCard->cbTurnOver>0);
}
//更新叫分按钮;
void DZGameScene::updateCallButtons(uint16 wCurChairID, uint8 cbLastCallScore)
{
//转换当前玩家视图;
uint16 wCurViewID = SwitchViewChairID(wCurChairID);
//如果当前是自已显示叫分按钮;
if (DZ_SELF_VIEW_ID == wCurViewID)
{
if (255 == cbLastCallScore)
{
//显示按钮;
m_pBtnCallScore->setVisible(true);
m_pBtnPassCall->setVisible(true);
}
//显示当前玩家倒计时;
m_aryPlayer[wCurViewID]->showClock(m_cbTimeCallScore, [=](void){
// 在托管状态超时发送不包牌消息;
if (m_aryTrustee[DZ_SELF_VIEW_ID])
{
SendPassCall();
}
});
}
else if (wCurViewID<DZ_GAME_PLAYER)
{
m_aryPlayer[wCurViewID]->showClock(m_cbTimeCallScore);
}
}
//更新按钮状态;
void DZGameScene::updateButtonsStatus(uint16 wCurChairID, uint8 cbLeftSeconds, bool bTurnOver/* = false*/)
{
//转换当前玩家视图;
uint16 wCurViewID = SwitchViewChairID(wCurChairID);
CC_ASSERT(wCurViewID < DZ_GAME_PLAYER);
m_aryPlayer[wCurViewID]->setPassVisible(false);
//如果当前玩家是自已则显示出牌面板;
if (DZ_SELF_VIEW_ID == wCurViewID)
{
m_pBtnPass->setVisible(true);
m_pBtnPass->setEnabled(!bTurnOver);
m_pBtnTips->setVisible(true);
m_pBtnOutCard->setVisible(true);
//m_pBtnOutCard->setEnabled(false);
if (!bTurnOver)
{
////搜索出牌;
//tagDZSearchResult mCardResult;
//uint8 cbResultCount = m_GameLogic.SearchOutCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID],
// m_cbTurnCardData, m_cbTurnCardCount, mCardResult);
//if (cbResultCount == 0)
//{
// m_pSprTips->setVisible(true);
// if (m_cbTurnCardCount > 0)
// {
// m_pSprTips->setTexture(DZ_TIPS_ONLY_PASS_PNG_FILE);
// }
// m_pBtnTips->setEnabled(false);
// m_pBtnOutCard->setEnabled(false);
//}
//else
{
m_pBtnTips->setEnabled(true);
checkOutCardButton();
}
}
else
{
m_pBtnTips->setEnabled(false);
checkOutCardButton();
}
if (m_aryTrustee[DZ_SELF_VIEW_ID])
{
cbLeftSeconds = 1;
}
//显示自已倒计时;
m_aryPlayer[wCurViewID]->showClock(cbLeftSeconds, CC_CALLBACK_0(DZGameScene::autoOutCard, this));
}
else
{
//显示其它玩家倒计时;
m_aryPlayer[wCurViewID]->showClock(cbLeftSeconds);
}
}
//隐藏出牌按钮;
void DZGameScene::hideOutCardButtons()
{
m_pSprTips->setVisible(false);
m_pBtnPass->setVisible(false);
m_pBtnTips->setVisible(false);
m_pBtnOutCard->setVisible(false);
m_pPanleMoveOutCard->setVisible(false);
}
//隐藏出牌按钮;
void DZGameScene::checkOutCardButton()
{
uint8 aryShootCardData[DZ_MAX_COUNT] = { 0 };
uint8 cbShootCardCount = 0;
bool isLastCard = false;
m_pHandCardLayer->getShootCardData(aryShootCardData, cbShootCardCount);
isLastCard = (m_pHandCardLayer->getHandCardCount() == cbShootCardCount);
if (cbShootCardCount==0)
{
m_pSprTips->setVisible(true);
m_pSprTips->setTexture(DZ_TIPS_CHOOSECARD_PNG_FILE);
m_pBtnOutCard->setEnabled(false);
m_pPanleMoveOutCard->setVisible(false);
return;
}
// 牌型检测前必须排序;
m_GameLogic.SortCardList(aryShootCardData, cbShootCardCount, DZ_ST_ORDER);
int cbCardType = m_GameLogic.GetCardType(aryShootCardData, cbShootCardCount, isLastCard);
if (cbCardType == DZ_CT_ERROR)
{
m_pSprTips->setVisible(true);
m_pSprTips->setTexture(DZ_TIPS_OUT_ERROR_PNG_FILE);
m_pBtnOutCard->setEnabled(false);
m_pPanleMoveOutCard->setVisible(false);
return;
}
else
{
m_pSprTips->setVisible(false);
}
if (m_TurnOutCard.cbCardCount > 0)
{
DZ_CMD_C_OutCard outCard;
zeromemory(&outCard, sizeof(DZ_CMD_C_OutCard));
CopyMemory(outCard.cbCardData, aryShootCardData, sizeof(uint8)*cbShootCardCount);
outCard.cbCardCount = cbShootCardCount;
outCard.cbCardType = cbCardType;
outCard.isLastCard = isLastCard;
bool bRet = m_GameLogic.CompareCard(&m_TurnOutCard, &outCard);
if (bRet)
{
m_pBtnOutCard->setEnabled(true);
}
else
{
m_pBtnOutCard->setEnabled(false);
m_pPanleMoveOutCard->setVisible(false);
}
}
else
{
BYTE cbTypeCount = 0;
for (BYTE i = 0; i < MOVE_BTN_OUT_CARD_COUNT; i++)
{
int bTmpCardType = g_MoveBtnOutCards[i];
std::string strKey = StringUtils::format("btnOutCard_%d", bTmpCardType);
auto btnOutCard = static_cast<Button*>(m_pPanleMoveOutCard->getChildByName(strKey));
if ((cbCardType&(1 << bTmpCardType)) != 0)
{
btnOutCard->setEnabled(true);
cbTypeCount++;
}
else
{
btnOutCard->setEnabled(false);
}
}
if (cbTypeCount <= 1)
{
m_pBtnOutCard->setEnabled(true);
m_pPanleMoveOutCard->setVisible(false);
}
else if (cbTypeCount > 1)
{
m_pPanleMoveOutCard->setVisible(true);
}
}
}
//游戏结束;
void DZGameScene::onSubGameEnd(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_GameConclude));
DZ_CMD_S_GameConclude* pGameEnd = (DZ_CMD_S_GameConclude*)pBuffer;
m_pBtnTrustee->setVisible(false);
std::string aryNickName[DZ_GAME_PLAYER] = {};
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
uint16 wViewID = SwitchViewChairID(i);
DZ_GamePlayer* pPlayer = m_aryPlayer[wViewID];
aryNickName[i] = pPlayer->GetNickName();
m_aryPlayer[wViewID]->killClock();
}
uint16 wMyChairID = getSelfChairID();
if (pGameEnd->lGameScore[wMyChairID] > 0)
{
playSoundEffect(DZ_ST_WIN);
}
else
{
playSoundEffect(DZ_ST_LOSE);
}
if (pGameEnd->isPrivateEnd)
{
m_pResultLayer->SetShowPrivate();
}
if (m_wFriendChairID == INVALID_CHAIR)
{
uint16 wSelfChairID = getSelfChairID();
m_wFriendChairID = pGameEnd->wFriendChairID[wSelfChairID];
}
m_pResultLayer->show(m_wLandChairID, m_bNobodyCall, wMyChairID, m_wFriendChairID, aryNickName, pGameEnd, m_cbTimeStartGame);
// 动画回调;
PlayGameEndAni(pGameEnd->iGameEndType, [this](){
m_pResultLayer->setVisible(true);
m_bGameStart = false;
//m_pBtnReady->setEnabled(true);
//m_pBtnReady->setVisible(true);
});
}
//玩家托管;
void DZGameScene::onSubTrustee(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_Trustee));
DZ_CMD_S_Trustee* pTrustee = (DZ_CMD_S_Trustee*)pBuffer;
uint16 wViewID = SwitchViewChairID(pTrustee->wTrusteeUser);
m_aryTrustee[wViewID] = pTrustee->bTrustee;
//设置状态;
m_aryPlayer[wViewID]->setTrustVisible(m_aryTrustee[wViewID]);
if (DZ_SELF_VIEW_ID == wViewID)
{
if (m_aryTrustee[wViewID])
{
m_pPanelTrustee->setVisible(true);
m_pHandCardLayer->downAllCard();
if (getSelfChairID() == m_wCurChairID)
{
autoOutCard();
}
m_pBtnTrustee->setTitleText(utility::a_u8("取消托管"));
}
else
{
m_pPanelTrustee->setVisible(false);
m_pBtnTrustee->setTitleText(utility::a_u8("托管"));
}
}
}
//排名;
void DZGameScene::onSubRanking(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(DZ_CMD_S_Ranking));
DZ_CMD_S_Ranking* pRanking = (DZ_CMD_S_Ranking*)pBuffer;
uint16 wViewID = SwitchViewChairID(pRanking->wChairID);
m_aryPlayer[wViewID]->showRanking(pRanking->cbRanking);
}
// 玩家进入;
void DZGameScene::OnEventUserEnter(GamePlayer * pPlayer)
{
if (pPlayer == nullptr) return;
cocos2d::log(a_u8c("用户%s 进入status = %d, chair = %d."), pPlayer->GetNickName().c_str(), pPlayer->GetUserStatus(), pPlayer->GetChairID());
// 玩家桌子号和椅子号;
if (pPlayer->GetTableID() == INVALID_TABLE || pPlayer->GetChairID() == INVALID_CHAIR) return;
// 自己进入;
if (pPlayer->GetUserID() == getSelfGamePlayer()->GetUserID())
{
uint8 cbUserStatus = pPlayer->GetUserStatus();
m_pBtnReady->setVisible(cbUserStatus == US_SIT);
//if (cbUserStatus >= US_SIT)
//{
// // 匹配场必须匹配之后去请求场景消息,不然不会开始游戏;
// if (IsAllowAvertCheatMode())
// {
// m_kGameMission.OnGFGameOption();
// }
//}
}
}
//玩家状态改变;
void DZGameScene::OnEventUserStatus(GamePlayer * pPlayer)
{
if ( pPlayer->GetChairID() == getSelfChairID() )
{
//更新准备按钮状态;
if (pPlayer->GetUserStatus() >= US_READY)
{
m_pBtnReady->setVisible(false);
}
}
//std::string strIps[DZ_GAME_PLAYER] = {};
//std::string strNickNames[DZ_GAME_PLAYER] = {};
//
//// 同IP判断;
//if ((m_PrivateRoomInfo.dwPlayCout <= 0) && !m_PrivateRoomInfo.bStartGame)
//{
// IsSameIp();
//}
}
// 玩家离开;
void DZGameScene::OnEventUserLeave(GamePlayer * pPlayer)
{
}
// 同IP判断;
void DZGameScene::IsSameIp()
{
//if (IsAllowAvertCheatMode()) return;
std::string strIps[DZ_GAME_PLAYER] = {};
std::string strNickNames[DZ_GAME_PLAYER] = {};
// 同IP判断;
for (WORD i = 0; i < DZ_GAME_PLAYER; i++)
{
GamePlayer* pPlayer = getPlayerByChairID(i);
if (pPlayer)
{
strIps[i] = pPlayer->GetLogonIp();
strNickNames[i] = pPlayer->GetNickName(false);
}
}
bool bSameIp = false;
for (WORD i = 0; i < DZ_GAME_PLAYER; i++)
{
WORD wNext = (i + 1) % DZ_GAME_PLAYER;
if ((strIps[i] != "") && (strIps[i] == strIps[wNext]))
{
bSameIp = true;
break;
}
}
if (bSameIp)
{
IpTipScene::Instance().show(strNickNames, strIps, DZ_GAME_PLAYER);
}
else if (IpTipScene::Instance().isVisible())
{
IpTipScene::Instance().setVisible(false);
}
}
//自动出牌;
void DZGameScene::autoOutCard()
{
// 不在托管状态不出牌;
if ( false==m_aryTrustee[DZ_SELF_VIEW_ID] )
{
return;
}
if (getSelfChairID() != m_wCurChairID)
{
CC_ASSERT(false);
return;
}
////如果是自已出牌;
//if (m_wTurnWiner == m_wCurChairID && 0 == m_cbTurnCardCount)
//{
// uint8 cbLeftCard = m_aryHandCardCount[DZ_SELF_VIEW_ID];
// CC_ASSERT(cbLeftCard > 0 && cbLeftCard <= DZ_MAX_COUNT);
// DZ_CMD_C_OutCard OutCard;
// zeromemory(&OutCard, sizeof(DZ_CMD_C_OutCard));
// OutCard.cbCardCount = 1;
// OutCard.cbCardData[0] = m_bMustOutCard0x34 ? 0x34 : m_aryHandCardData[cbLeftCard - 1];
// uint16 wHeadSize = sizeof(DZ_CMD_C_OutCard) - sizeof(OutCard.cbCardData);
// uint16 wSendSize = wHeadSize + sizeof(uint8)*OutCard.cbCardCount;
// SendSocketData(DZ_SUB_C_OUT_CARD, &OutCard, wSendSize);
//}
//else
//{
// //搜索出牌;
// tagDZSearchCardResult mCardResult;
// uint8 cbResultCount = m_GameLogic.SearchOutCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID],
// m_cbTurnCardData, m_cbTurnCardCount, &mCardResult);
// if (cbResultCount > 0)
// {
// DZ_CMD_C_OutCard OutCard;
// zeromemory(&OutCard, sizeof(DZ_CMD_C_OutCard));
// OutCard.cbCardCount = mCardResult.cbCardCount[0];
// memcpy(OutCard.cbCardData, mCardResult.cbResultCard[0], OutCard.cbCardCount);
// uint16 wHeadSize = sizeof(DZ_CMD_C_OutCard) - sizeof(OutCard.cbCardData);
// uint16 wSendSize = wHeadSize + sizeof(uint8)*OutCard.cbCardCount;
// SendSocketData(DZ_SUB_C_OUT_CARD, &OutCard, wSendSize);
// }
// else
// {
// SendSocketData(DZ_SUB_C_PASS_CARD);
// }
//}
}
//解析分享内容;
void DZGameScene::parseShareContent(std::string& strContent)
{
std::string strRoomID = StringUtils::format("%u", m_PrivateRoomInfo.dwRoomNum);
utility::StringReplace(strContent, "%roomid%", strRoomID);
std::string strPlayCount = StringUtils::format("%d", m_PrivateRoomInfo.dwPlayTotal);
utility::StringReplace(strContent, "%playcount%", strPlayCount);
std::string strCurTime = JniFun::getSystemTime();
utility::StringReplace(strContent, "%curtime%", strCurTime);
GamePlayer* pPlayer = getSelfGamePlayer();
if ( pPlayer!=nullptr )
{
std::string strNickName = pPlayer->GetNickName();
utility::StringReplace(strContent, "%nickname%", strNickName);
}
}
//玩家金币改变;
void DZGameScene::OnUserScore(GamePlayer* pPlayer)
{
CC_ASSERT(pPlayer!=nullptr);
if (pPlayer == nullptr) return;
// 不再桌子上;
CC_ASSERT(pPlayer->GetTableID() != INVALID_TABLE && pPlayer->GetChairID() != INVALID_CHAIR);
if (pPlayer->GetTableID() == INVALID_TABLE || pPlayer->GetChairID() == INVALID_CHAIR) return;
// 不是同一桌子玩家;
CC_ASSERT(pPlayer->GetTableID() == getSelfGamePlayer()->GetTableID());
if (pPlayer->GetTableID() != getSelfGamePlayer()->GetTableID()) return;
cocos2d::log(a_u8c("用户%sscore = %d"), pPlayer->GetNickName().c_str(), pPlayer->GetUserScore());
//((DZ_GamePlayer*)pPlayer)->updateScore(!IsAllowAvertCheatMode());
((DZ_GamePlayer*)pPlayer)->updateScore(true);
}
// 玩家坐标;
Vec2 DZGameScene::GetPlayerPosByUserID(uint32 dwUserID)
{
DZ_GamePlayer* pPlayer = (DZ_GamePlayer*)getPlayerByUserID(dwUserID);
if (pPlayer == nullptr)
{
return Vec2();
}
const Vec2& ptHeadPos = pPlayer->getHeadPos();
Vec2 ptWorldPos = pPlayer->convertToWorldSpace(ptHeadPos);
return Vec2(ptWorldPos);
}
//调用;
GamePlayer* DZGameScene::CreatePlayer(IClientUserItem * pIClientUserItem)
{
//if (pIClientUserItem->GetChairID() == INVALID_CHAIR)
//{
// return NULL;
//}
if (pIClientUserItem->GetUserID() == UserInfo::Instance().getUserID())
{
m_pLocalPlayer->setUserItem(pIClientUserItem);
return m_pLocalPlayer;
}
else
{
WORD wViewID = SwitchViewChairID(pIClientUserItem->GetChairID());
CC_ASSERT(wViewID!=INVALID_CHAIR);
DZ_GamePlayer* pPlayer = m_aryPlayer[wViewID];
pPlayer->setUserItem(pIClientUserItem);
return pPlayer;
}
return NULL;
}
//椅子号视图转换;
WORD DZGameScene::SwitchViewChairID(WORD wChairID)
{
//参数判断;
if (wChairID == INVALID_CHAIR) return INVALID_CHAIR;
WORD wSelfChairID = getSelfChairID();
if (wSelfChairID == INVALID_CHAIR) return INVALID_CHAIR;
//转换椅子;
WORD wChairCount = DZ_GAME_PLAYER;
WORD wViewChairID = (wChairID + wChairCount * 3 / 2 - wSelfChairID) % wChairCount;
return wViewChairID;
}
//本人进入游戏 GameFrameBase.cpp调用;
void DZGameScene::upSelfPlayerInfo()
{
log("Self Enter!!");
return;
}
//不叫消息;
void DZGameScene::SendPassCall()
{
DZ_CMD_C_CallScore call;
call.cbCallScore = 0xFF;
SendSocketData(DZ_SUB_C_CALL_SCORE, &call, sizeof(DZ_CMD_C_CallScore));
}
//发牌;
void DZGameScene::moveSendCardSprite(Sprite* pCardSprite, uint16 wViewID, float fDelayTime)
{
float fEndPosX = 0.f, fEndPosY = 0.f;
// 计算位置;
if (wViewID == DZ_SELF_VIEW_ID)
{
Node* pHandCardPanel = m_pHandCardLayer->getParent();
CC_ASSERT(pHandCardPanel!=nullptr);
int iHandCardSpace = m_pHandCardLayer->getHandCardSpace(DZ_NORMAL_COUNT);
int iStartPosX = pHandCardPanel->getPositionX();// -(iHandCardWidth / 2);
fEndPosX = (iStartPosX + pCardSprite->getContentSize().width*0.35f + pCardSprite->getTag() / 4 * iHandCardSpace)*0.8;
fEndPosY = pHandCardPanel->getPositionY() + pHandCardPanel->getContentSize().height / 2;
}
else
{
fEndPosX = m_aryPlayer[wViewID]->getCardPos().x;
fEndPosY = m_aryPlayer[wViewID]->getCardPos().y;
}
//auto pAction = Spawn::create(MoveTo::create(0.2f, Vec2(fEndPosX, fEndPosY)), RotateBy::create(0.2f, 180), nullptr);
auto pAction = MoveTo::create(0.2f, Vec2(fEndPosX, fEndPosY));
auto fnShowAllCard = [=](Node * pNode)
{
pNode->stopAllActions();
m_GameLogic.SortCardList(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID], m_nSort);
m_pHandCardLayer->redrawHandCard(m_aryHandCardData, m_aryHandCardCount[DZ_SELF_VIEW_ID]);
m_pBtnSort->setVisible(true); // 显示牌型按钮;
////更新叫分按钮;
//if ((m_PrivateRoomInfo.bGameRuleIdex&eDZRuleEnum_NO_JOKER) > 0)
//{
// updateCallButtons(m_wCurChairID, 255);
//}
};
auto callback = [=](Node* pNode)
{
m_aryHandCardCount[wViewID]++;
m_aryPlayer[wViewID]->setHandCardCount(m_aryHandCardCount[wViewID], !m_IsGameRecord);
pNode->removeFromParent();
//玩家自己;
if (wViewID == DZ_SELF_VIEW_ID)
{
m_pHandCardLayer->addSendCard2Panel();
//发牌完成延时0.2秒显示手牌数据;
if (m_aryHandCardCount[wViewID] == m_aryTempCardCount[wViewID])
{
this->runAction(Sequence::create(DelayTime::create(0.2f), CallFuncN::create(fnShowAllCard), nullptr));
}
}
};
Action* pCardAction = Sequence::create(DelayTime::create(fDelayTime), pAction, CallFuncN::create(callback), nullptr);
pCardSprite->runAction(pCardAction);
}
//选牌回调;
void DZGameScene::selectCardCallback(uint8* arySelCardData, uint8 cbSelCardCount)
{
//播放点牌音效;
playSoundEffect(DZ_ST_CLICK_CARD);
if ( getSelfChairID()!=m_wCurChairID )
{
return;
}
checkOutCardButton();
}
//播放动画;
void DZGameScene::playAnimate(int cbCardType, uint16 wFromChair, uint16 wToChair)
{
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
uint16 wFromViewID = SwitchViewChairID(wFromChair);
uint16 wToViewID = SwitchViewChairID(wToChair);
DZ_GamePlayer* pFromUserItem = (wFromViewID != INVALID_CHAIR)?m_aryPlayer[wFromViewID]:nullptr;
DZ_GamePlayer* pToUserItem = (wToViewID != INVALID_CHAIR) ? m_aryPlayer[wToViewID] : nullptr;
const Size& winSize = Director::getInstance()->getWinSize();
//顺子类型;
if ((cbCardType&(1 << DZ_CT_SINGLE_LINE)) != 0)
{
if (pFromUserItem!=nullptr)
{
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Ani/AniLine.plist");
Sprite* pImgLineAni = Sprite::createWithSpriteFrameName("imgAniLine1.png");
if (wFromViewID == DZ_LEFT_VIEW_ID)
{
pImgLineAni->setAnchorPoint(Vec2(0.0f, 0.5f));
}
else if (wFromViewID == DZ_SELF_VIEW_ID)
{
pImgLineAni->setAnchorPoint(Vec2(0.5f, 0.5f));
}
else if (wFromViewID == DZ_RIGHT_VIEW_ID)
{
pImgLineAni->setAnchorPoint(Vec2(1.0f, 0.5f));
}
pImgLineAni->setPosition(pFromUserItem->getOutCardPos());
pFromUserItem->addChild(pImgLineAni);
auto pLineAni = Animation::create();
pLineAni->setDelayPerUnit(0.1f);
for (uint8 i = 1; i <= 10; i++)
{
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniLine%d.png", i));
pLineAni->addSpriteFrame(pSpriteFrame);
}
pImgLineAni->runAction(Sequence::create(Animate::create(pLineAni), RemoveSelf::create(), nullptr));
}
}
//连对类型;
else if ((cbCardType&(1 << DZ_CT_DOUBLE_LINE)) != 0)
{
if (pFromUserItem != nullptr)
{
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Ani/AniDouble.plist");
auto pImgDoubleAni = Sprite::createWithSpriteFrameName("imgAniDouble1.png");
if (wFromViewID == DZ_LEFT_VIEW_ID)
{
pImgDoubleAni->setAnchorPoint(Vec2(0, 0.5f));
}
else if (wFromViewID == DZ_SELF_VIEW_ID)
{
pImgDoubleAni->setAnchorPoint(Vec2(0.5f, 0.5f));
}
else if (wFromViewID == DZ_RIGHT_VIEW_ID)
{
pImgDoubleAni->setAnchorPoint(Vec2(1.0f, 0.5f));
}
pImgDoubleAni->setPosition(pFromUserItem->getOutCardPos());
pFromUserItem->addChild(pImgDoubleAni);
auto pDoubleAni = Animation::create();
pDoubleAni->setDelayPerUnit(0.15f);
for (uint8 i = 1; i <= 9; i++)
{
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniDouble%d.png", i));
pDoubleAni->addSpriteFrame(pSpriteFrame);
}
pImgDoubleAni->runAction(Sequence::create(Animate::create(pDoubleAni), RemoveSelf::create(), nullptr));
}
}
else if ((cbCardType&(1 << DZ_CT_THREE_LINE)) != 0) //飞机类型
{
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Ani/AniPlane.plist");
auto pImgPlaneSprite = Sprite::createWithSpriteFrameName("imgAniPlane1.png");
pImgPlaneSprite->setAnchorPoint(Vec2(1.0f, 0.5f));
pImgPlaneSprite->setPosition(0.0f, winSize.height / 2);
m_rootNode->addChild(pImgPlaneSprite);
auto pImgPlaneAni1 = Sprite::createWithSpriteFrameName("imgAniPlane2.png");
pImgPlaneAni1->setPosition(390, 130);
pImgPlaneSprite->addChild(pImgPlaneAni1);
auto pPlaneAni1 = Animation::create();
pPlaneAni1->setDelayPerUnit(0.1f);
pPlaneAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane2.png"));
pPlaneAni1->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane3.png"));
pImgPlaneAni1->runAction(RepeatForever::create(Animate::create(pPlaneAni1)));
auto pImgPlaneAni2 = Sprite::createWithSpriteFrameName("imgAniPlane4.png");
pImgPlaneAni2->setPosition(-55, 150);
pImgPlaneSprite->addChild(pImgPlaneAni2);
auto pPlaneAni2 = Animation::create();
pPlaneAni2->setDelayPerUnit(0.1f);
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane4.png"));
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane5.png"));
pPlaneAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniPlane6.png"));
pImgPlaneAni2->runAction(RepeatForever::create(Animate::create(pPlaneAni2)));
Action* pAction = Sequence::create(MoveBy::create(1.5f, Vec2(winSize.width + 380, 0)), RemoveSelf::create(), nullptr);
pImgPlaneSprite->runAction(pAction);
}
//炸弹类型;
else if ((cbCardType >> DZ_CT_BOMB_4) > 0 )
{
Vec2 ptEndBombPos = Vec2::ZERO;
if (wFromChair == wToChair)
{
ptEndBombPos.x = winSize.width / 2;
ptEndBombPos.y = winSize.height / 2;
}
else
{
if (pToUserItem != nullptr)
{
ptEndBombPos = pToUserItem->getHeadPos();
ptEndBombPos = pToUserItem->convertToWorldSpace(ptEndBombPos);
}
}
if (pFromUserItem != nullptr )
{
pSpriteFrameCache->addSpriteFramesWithFile("Games/DaZha/Ani/AniBomb.plist");
Vec2 ptBeginBombPos = pFromUserItem->getHeadPos();
ptBeginBombPos = pFromUserItem->convertToWorldSpace(ptBeginBombPos);
Sprite* pImgBombAni = Sprite::createWithSpriteFrameName("imgAniBomb1.png");
pImgBombAni->setPosition(ptBeginBombPos);
m_rootNode->addChild(pImgBombAni);
ccBezierConfig tabMovePos = { ptEndBombPos, Vec2(winSize.width / 2, winSize.height / 2), ptBeginBombPos };
EaseSineIn* pMoveAction = EaseSineIn::create(BezierTo::create(0.5f, tabMovePos));
Spawn* pSpawnAction = Spawn::create(RotateBy::create(0.5f, 720), pMoveAction, nullptr);
auto bombFunc = [=](){
if (wFromChair == wToChair)
{
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
if (i != wFromViewID)
{
Sprite* pImgBombAni2 = Sprite::createWithSpriteFrameName("imgAniBomb15.png");
const Vec2& ptHeadPos = m_aryPlayer[i]->getHeadPos();
pImgBombAni2->setScale(1.4f);
pImgBombAni2->setPositionX(ptHeadPos.x);
pImgBombAni2->setPositionY(ptHeadPos.y + 4);
m_aryPlayer[i]->addChild(pImgBombAni2);
auto pBombAni2 = Animation::create();
pBombAni2->setDelayPerUnit(0.1f);
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb15.png"));
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb16.png"));
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb17.png"));
Action* pAction = Sequence::create(Repeat::create(Animate::create(pBombAni2), 2), RemoveSelf::create(), nullptr);
pImgBombAni2->runAction(pAction);
}
}
}
else
{
if (pToUserItem != nullptr)
{
Sprite* pImgBombAni2 = Sprite::createWithSpriteFrameName("imgAniBomb15.png");
const Vec2& ptHeadPos = pToUserItem->getHeadPos();
pImgBombAni2->setScale(1.4f);
pImgBombAni2->setPositionX(ptHeadPos.x);
pImgBombAni2->setPositionY(ptHeadPos.y + 4);
pToUserItem->addChild(pImgBombAni2);
auto pBombAni2 = Animation::create();
pBombAni2->setDelayPerUnit(0.1f);
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb15.png"));
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb16.png"));
pBombAni2->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName("imgAniBomb17.png"));
Action* pAction = Sequence::create(Repeat::create(Animate::create(pBombAni2), 2), RemoveSelf::create(), nullptr);
pImgBombAni2->runAction(pAction);
}
}
};
auto callback = [=](){
//震动/闪屏;
m_rootNode->runAction(ShakeBy::create(0.5f, Vec2(10, 10)));
if (UserInfo::Instance().m_isShake)
{
Device::vibrate(0.4f);
}
Sprite* pImgBombAni1 = Sprite::createWithSpriteFrameName("imgAniBomb3.png");
if (wFromChair == wToChair)
{
pImgBombAni1->setPosition(ptEndBombPos);
m_rootNode->addChild(pImgBombAni1);
}
else
{
if (pToUserItem != nullptr)
{
pImgBombAni1->setPosition(pToUserItem->getHeadPos());
}
pToUserItem->addChild(pImgBombAni1);
}
auto pBombAni1 = Animation::create();
pBombAni1->setDelayPerUnit(0.1f);
for (uint8 i = 3; i <= 14; i++)
{
SpriteFrame* pSpriteFrame = pSpriteFrameCache->getSpriteFrameByName(StringUtils::format("imgAniBomb%d.png", i));
pBombAni1->addSpriteFrame(pSpriteFrame);
}
Action* pAction = Sequence::create(Animate::create(pBombAni1), RemoveSelf::create(), CallFunc::create(bombFunc), nullptr);
pImgBombAni1->runAction(pAction);
};
pImgBombAni->runAction(Sequence::create(pSpawnAction, RemoveSelf::create(), CallFunc::create(callback), nullptr));
}
}
}
//结算动画;
void DZGameScene::PlayGameEndAni(DZ_GAME_END_TYPE enGameEndType, const std::function<void()>& callback)
{
string strFileName = "";
switch (enGameEndType)
{
case DZ_GAME_END_NULL:
break;
case DZ_GAME_END_ONE_WIN:
strFileName = "Games/DaZha/Result/imgEndTitle1.png";
break;
case DZ_GAME_END_TWO_WIN:
strFileName = "Games/DaZha/Result/imgEndTitle2.png";
break;
case DZ_GAME_END_DRAW:
strFileName = "Games/DaZha/Result/imgEndTitle3.png";
break;
case DZ_GAME_END_NO_BOMB:
strFileName = "Games/DaZha/Table/imgNoBomb.png";
break;
case DZ_GAME_END_8_BOMB:
strFileName = "Games/DaZha/Table/img8Bomb.png";
break;
default:
break;
}
Texture2D* pTexture = Director::getInstance()->getTextureCache()->addImage(strFileName);
if (pTexture)
{
CallFunc* tmpBack = CallFunc::create(callback);
m_imgGameEndAni->setScale(0.8f);
m_imgGameEndAni->setTexture(pTexture);
m_imgGameEndAni->setVisible(true);
auto act = EaseElasticOut::create(ScaleTo::create(0.6f, 1.0f));
m_imgGameEndAni->runAction(Sequence::create(act, DelayTime::create(0.5f), Hide::create(), tmpBack, nullptr));
}
}
void DZGameScene::playSoundEffect(const int cbCardType, uint8 cbSex/*=1*/, const uint8 cbData/*=0*/, const bool isOutCard /*= false*/)
{
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
std::string strSoundFile;
if (cbSex > 0)
{
cbSex--;
}
if (isOutCard)
{
if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_SINGLE))
{
int nFlagID = 0;
//小王;
if (CARD_LITTLE_JOKER == cbData)
{
nFlagID = 14;
}
//大王;
else if (CARD_LITTLE_JOKER == cbData)
{
nFlagID = 15;
}
else
{
nFlagID = m_GameLogic.GetCardValue(cbData);
}
strSoundFile = StringUtils::format(DZ_DANZHANG_FILE, cbSex, nFlagID);
}
else if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_DOUBLE))
{
//int nFlagID = m_GameLogic.GetCardValue(cbData);
int nFlagID = 0;
//小王;
if (CARD_LITTLE_JOKER == cbData)
{
nFlagID = 14;
}
//大王;
else if (CARD_LITTLE_JOKER == cbData)
{
nFlagID = 15;
}
else
{
nFlagID = m_GameLogic.GetCardValue(cbData);
}
strSoundFile = StringUtils::format(DZ_LIANGZHANG_FILE, cbSex, nFlagID);
}
else if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_SINGLE_LINE))
{
pAudio->playEffect(DZ_SHUNZI_EFF_FILE);
strSoundFile = StringUtils::format(DZ_SHUNZI_FILE, cbSex);
}
else if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_DOUBLE_LINE))
{
pAudio->playEffect(DZ_LIANDUI_EFF_FILE);
strSoundFile = StringUtils::format(DZ_LIANDUI_FILE, cbSex);
}
else if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_THREE_TAKE_TWO))
{
strSoundFile = StringUtils::format(DZ_3DAI2_FILE, cbSex);
}
else if (m_GameLogic.IsHasCardType(cbCardType, DZ_CT_THREE_LINE))
{
strSoundFile = StringUtils::format(DZ_FEIJI_FILE, cbSex);
pAudio->playEffect(DZ_FEIJI_EFF_FILE);
}
else if ((cbCardType >> DZ_CT_BOMB_4) > 0)
{
pAudio->playEffect(DZ_ZHADAN_EFF_FILE);
strSoundFile = StringUtils::format(DZ_ZHADAN_FILE, cbSex);
}
}
else
{
switch (cbCardType)
{
case DZ_ST_DEAL_CARD:
{
strSoundFile = DZ_FAPAI_EFF_FILE;
break;
}
case DZ_ST_PASS:
{
int nSoundID = (rand() % 4) + 1;
strSoundFile = StringUtils::format(DZ_PASS_FILE, cbSex, nSoundID);
break;
}
case DZ_ST_CALL:
{
if (cbData <= 3)
{
strSoundFile = StringUtils::format(DZ_JIAO_FEN_FILE, cbSex, cbData);
}
else
{
strSoundFile = StringUtils::format(DZ_BUJIAO_FILE, cbSex);
}
break;
}
case DZ_ST_CLICK_CARD:
{
strSoundFile = DZ_DIANPAI_EFF_FILE;
break;
}
case DZ_ST_OUT_CARD:
{
strSoundFile = DZ_CHUPAI_EFF_FILE;
break;
}
case DZ_ST_LEFT_ONE_CARD:
{
strSoundFile = StringUtils::format(DZ_ZUIHOUYIZHANG_FILE, cbSex);
break;
}
case DZ_ST_WIN:
{
strSoundFile = DZ_WIN_EFF_FILE;
break;
}
case DZ_ST_LOSE:
{
strSoundFile = DZ_LOSE_EFF_FILE;
break;
}
}
}
//CC_ASSERT(!strSoundFile.empty());
if (!strSoundFile.empty())
{
pAudio->playEffect(strSoundFile.c_str());
}
//SimpleAudioEngine::getInstance()->playEffect(fillpath,isRe);
}
/************************************* 语音 ***********************************************************/
// 按住语音按钮;
void DZGameScene::OnButtonVoiceTouched(Ref*, Widget::TouchEventType type)
{
if (Widget::TouchEventType::BEGAN == type)
{
// 暂停播放背景音乐;
CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
if (m_pVoiceNode->isVisible())
{
m_pVoiceNode->setVisible(false);
m_pVoiceNode->stopAllActions();
YvVoiceManager::GetInstance()->StopRecord();
return;
}
m_pVoiceNode->setVisible(true);
// 启动帧动画;
auto action = CSLoader::createTimeline("Games/DaZha/VoiceNode.csb");
action->gotoFrameAndPlay(0);
m_pVoiceNode->runAction(action);
YvVoiceManager::GetInstance()->StartRecord();
}
else if ((Widget::TouchEventType::CANCELED == type) || (Widget::TouchEventType::ENDED == type))
{
// 继续播放背景音乐;
CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
if (!m_pVoiceNode->isVisible())
{
return;
}
m_pVoiceNode->setVisible(false);
m_pVoiceNode->stopAllActions();
YvVoiceManager::GetInstance()->StopRecord();
}
}
/************************************* 房间信息 ***********************************************************/
// 房间信息消息;
void DZGameScene::OnSocketSubPrivateRoomInfo(CMD_GF_Private_Room_Info* pNetInfo)
{
m_PrivateRoomInfo = *pNetInfo;
m_dwRoomID = pNetInfo->dwRoomNum;
// 界面控制;
if (m_txtPrivateRoomID->isVisible() == false)
{
m_btnVoice->setVisible(true);
m_btnChat->setVisible(true);
//m_imgRule->setVisible(true);
//m_imgGameRule->setVisible(true);
// 房间号;
m_txtPrivateRoomID->setString(utility::a_u8(StringUtils::format("房号:%d", m_dwRoomID)));
m_txtPrivateRoomID->setVisible(true);
std::string strGameRule1 = "";
std::string strGameRule2 = "";
std::string strGameRule3 = "";
// 不带王、明边、只打二游规则;
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_NO_JOKER) > 0)
{
strGameRule1 = "不带王";
}
else
{
strGameRule1 = "带王";
}
// 明边;
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_MINGBIAN) > 0)
{
strGameRule1 += "、明边";
}
else
{
strGameRule1 += "、暗边";
}
// 只打二;
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_TO_TWO) > 0)
{
strGameRule1 += "、只打二游";
}
// 只打二;
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_NO_BOMB) > 0)
{
strGameRule2 += "无炸摊牌";
}
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_EIGHT_BOMB) > 0)
{
if (strGameRule2.length() > 0)
{
strGameRule2 += "";
}
strGameRule2 += "八炸摊牌";
}
// 开奖;
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_LOTTERY_7) > 0)
{
strGameRule3 += "7";
}
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_LOTTERY_10) > 0)
{
if (strGameRule3.length() > 0)
{
strGameRule3 += "";
}
strGameRule3 += "10";
}
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_LOTTERY_J) > 0)
{
if (strGameRule3.length() > 0)
{
strGameRule3 += "";
}
strGameRule3 += "J";
}
if ((pNetInfo->bGameRuleIdex&eDZRuleEnum_LOTTERY_K) > 0)
{
if (strGameRule3.length() > 0)
{
strGameRule3 += "";
}
strGameRule3 += "K";
}
m_txtGameRule1->setString(utility::a_u8(strGameRule1));
m_txtGameRule2->setString(utility::a_u8(strGameRule2));
std::string strLottery = "开奖:" + strGameRule3;
m_txtGameRule3->setString(utility::a_u8(strLottery));
DZ_GamePlayer* pPlayer = (DZ_GamePlayer*)getPlayerByUserID(pNetInfo->dwCreateUserID);
if (pPlayer != nullptr)
{
pPlayer->setOwnerVisible(true);
}
}
uint32 dwPlayCout = __max(pNetInfo->dwPlayCout+1, 1);
dwPlayCout = __min(dwPlayCout, pNetInfo->dwPlayTotal);
string strPlayCount = StringUtils::format("局数:%u/%u", dwPlayCout, pNetInfo->dwPlayTotal);
cocos2d::log("dwPlayCout = %d", pNetInfo->dwPlayCout);
m_txtPrivatePlayCount->setString(utility::a_u8(strPlayCount.c_str()));
m_txtPrivatePlayCount->setVisible(true);
if (pNetInfo->bStartGame)
{
//如果游戏已开始则隐藏“返回大厅”按钮,显示“解散房间”按钮;
m_btnWeiXin->setVisible(false);
m_pBtnLeave->setVisible(false);
m_btnDismissRoom->setVisible(true);
}
else
{
GamePlayer* pPlayer = getSelfGamePlayer();
//如果房间主人是自已则隐藏“返回大厅”按钮,显示“解散房间”按钮;
if (pPlayer != nullptr && pNetInfo->dwCreateUserID == pPlayer->GetUserID())
{
m_pBtnLeave->setVisible(false);
m_btnDismissRoom->setVisible(true);
}
//游戏未开始显示微信分享按钮;
m_btnWeiXin->setVisible(true);
}
if (m_IsGameRecord)
{
m_btnWeiXin->setVisible(false);
m_pBtnLeave->setVisible(false);
m_btnDismissRoom->setVisible(false);
m_pBtnTrustee->setVisible(false);
}
}
// 私人场结束;
void DZGameScene::OnSocketSubPrivateEnd(void* data, int dataSize)
{
m_bPrivateEnd = true;
// 申请解散界面
DismissScene::Instance().hide();
GamePlayer* players[DZ_GAME_PLAYER];
for (int i = 0; i < DZ_GAME_PLAYER; i++)
{
players[i] = getPlayerByChairID(i);
}
if (m_pPrivateScene)
{
DataStream kDataStream(data, dataSize);
DZ_CMD_S_Private_End_Info kNetInfo;
kNetInfo.StreamValue(kDataStream, false);
//SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
//m_pPrivateScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);
// 欢乐场
if (m_PrivateRoomInfo.cbUnionGoldOpen == 1)
{
SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
//m_pPrivateScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);
m_pPrivateScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo, m_PrivateScoreInfo);
}
else
{
m_pPrivateScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo.cbBaseScore);
}
m_pResultLayer->SetShowPrivate();
if (!m_pResultLayer->isVisible() && !m_bGameStart)
{
m_pPrivateScene->pushScene();
}
}
}
// 显示结算信息;
void DZGameScene::onEventShowPrivate(cocos2d::EventCustom *event)
{
if (m_pPrivateScene)
{
m_pPrivateScene->pushScene();
}
}
// 请求解散房间;
void DZGameScene::OnSocketSubPrivateDismissInfo(CMD_GF_Private_Dismiss_Info* pNetInfo)
{
std::string aryName[DZ_GAME_PLAYER];
BYTE aryResult[DZ_GAME_PLAYER] = { 0 }; // 0 未选择 1 同意 2 不同意
bool bHasSelf = false;
uint32 dwMyChairID = getSelfChairID();
for (uint32 i = 0; i < pNetInfo->dwDissUserCout; i++)
{
uint32 dwChairID = pNetInfo->dwDissChairID[i];
GamePlayer* pPlayer = getPlayerByChairID(dwChairID);
if (pPlayer != nullptr && dwChairID < DZ_GAME_PLAYER)
{
aryResult[dwChairID] = 1;
}
if (dwMyChairID == dwChairID)
{
bHasSelf = true;
}
}
for (uint32 i = 0; i < pNetInfo->dwNotAgreeUserCout; i++)
{
uint32 dwChairID = pNetInfo->dwNotAgreeChairID[i];
GamePlayer* pPlayer = getPlayerByChairID(dwChairID);
if (pPlayer != nullptr && dwChairID < DZ_GAME_PLAYER)
{
aryResult[dwChairID] = 2;
}
if (dwMyChairID == dwChairID)
{
bHasSelf = true;
}
}
GamePlayer* players[DZ_GAME_PLAYER];
for (int i = 0; i < DZ_GAME_PLAYER; i++)
{
players[i] = getPlayerByChairID(i);
}
DismissScene::Instance().show(aryResult, players, !bHasSelf, DZ_GAME_PLAYER);
}
// 解散结果;
void DZGameScene::OnSocketSubPrivateDismissResult(CMD_GF_Private_Dismiss_Result* pNetInfo)
{
if (pNetInfo->bSuccess && false == m_PrivateRoomInfo.bStartGame)
{
Director::getInstance()->popScene();
}
else
{
DismissScene::Instance().hide();
}
}
//////////////////////////////// 游戏录像 //////////////////////////////////////////
// 开始录像播放;
void DZGameScene::StartGameRecord()
{
if (m_GameRecord.playersVec.size() != DZ_GAME_PLAYER)
{
return;
}
// 初始化房间信息;
OnSocketSubPrivateRoomInfo(&m_GameRecord.roomInfo);
m_iActRecordIdex = 0;
m_txtRecordPercent->setString(utility::toString(m_iActRecordIdex * 100 / m_GameRecord.actionVec.size(), "%"));
schedule(schedule_selector(GameFrameBase::NextRecordAction), m_RecordTime);
return;
}
void DZGameScene::NextRecordAction(float dt)
{
cocos2d::log("NextRecordAction...m_iActRecordIdex = %d", m_iActRecordIdex);
// 已经播放完了;
if (m_iActRecordIdex >= (int)m_GameRecord.actionVec.size() || !isVisible())
{
m_txtRecordPercent->setString("100%");
m_btnPlay->setVisible(true);
m_btnPause->setVisible(false);
unschedule(schedule_selector(GameFrameBase::NextRecordAction));
return;
}
// 下一个操作记录;
tagGameRecordOperateResult& kAction = m_GameRecord.actionVec[m_iActRecordIdex];
// 游戏开始;
if (kAction.wSubCmdID == DZ_SUB_S_GAME_START)
{
m_cbTimeOutCard = 15;
m_cbTimeCallScore = 15;
m_cbTimeStartGame = 15;
m_cbTimeHeadOutCard = 15;
m_nCellScore = 1;
DZ_CMD_Record_GameStart recordStart;
kAction.subMessageData.popValue(&recordStart, sizeof(DZ_CMD_Record_GameStart));
DZ_CMD_S_GameStart gameStart;
zeromemory(&gameStart, sizeof(DZ_CMD_S_GameStart));
gameStart.wCurrentUser = recordStart.wCurrentUser;
for (int i = 0; i < DZ_GAME_PLAYER; i++)
{
gameStart.cbCardCount[i] = m_GameRecord.playersVec[i].cbCardData.size();
}
CC_ASSERT(m_wRecordSelfChairID != INVALID_CHAIR);
tagGameRecordPlayer& kRecordPlayer = m_GameRecord.playersVec[m_wRecordSelfChairID];
size_t tCardCount = kRecordPlayer.cbCardData.size();
for (int j = 0; j < (int)tCardCount; j++)
{
gameStart.cbCardData[j] = kRecordPlayer.cbCardData[j];
}
for (uint8 i = 0; i < DZ_GAME_PLAYER; i++)
{
uint16 wChairID = (m_wRecordSelfChairID + i) % DZ_GAME_PLAYER;
uint16 wViewID = SwitchViewChairID(wChairID);
tagGameRecordPlayer& kRecordPlayer2 = m_GameRecord.playersVec[wChairID];
size_t tCardCount2 = kRecordPlayer2.cbCardData.size();
for (int j = 0; j < (int)tCardCount2; j++)
{
m_aryAllHandCardData[wViewID][j] = kRecordPlayer2.cbCardData[j];
}
}
onSubGameStart(&gameStart, sizeof(DZ_CMD_S_GameStart));
}
// 玩家叫分;
else if (kAction.wSubCmdID == DZ_SUB_S_CALL_SCORE)
{
DZ_CMD_S_CallScore callCard;
zeromemory(&callCard, sizeof(DZ_CMD_S_CallScore));
kAction.subMessageData.popValue(&callCard, sizeof(DZ_CMD_S_CallScore));
onSubCallScore(&callCard, sizeof(DZ_CMD_S_CallScore));
}
// 确认庄家;
else if (kAction.wSubCmdID == DZ_SUB_S_BANKER_INFO)
{
DZ_CMD_S_BankerInfo bankerInfo;
zeromemory(&bankerInfo, sizeof(DZ_CMD_S_BankerInfo));
kAction.subMessageData.popValue(&bankerInfo, sizeof(DZ_CMD_S_BankerInfo));
onSubBankerInfo(&bankerInfo, sizeof(DZ_CMD_S_BankerInfo));
}
// 玩家出牌;
else if (kAction.wSubCmdID == DZ_SUB_S_OUT_CARD)
{
DZ_CMD_S_OutCard outCard;
zeromemory(&outCard, sizeof(outCard));
kAction.subMessageData.popValue(outCard.isLastCard);
kAction.subMessageData.popValue(outCard.cbCardType);
kAction.subMessageData.popValue(outCard.cbCardCount);
kAction.subMessageData.popValue(outCard.wCurrentUser);
kAction.subMessageData.popValue(outCard.wOutCardUser);
kAction.subMessageData.popValue(outCard.cbCardData, outCard.cbCardCount);
uint16 wHeadSize = sizeof(DZ_CMD_S_OutCard) - sizeof(outCard.cbCardData);
onSubOutCard(&outCard, (wHeadSize + outCard.cbCardCount*sizeof(uint8)));
}
// 玩家放弃出牌;
else if (kAction.wSubCmdID == DZ_SUB_S_PASS_CARD)
{
DZ_CMD_S_PassCard passCard;
zeromemory(&passCard, sizeof(passCard));
kAction.subMessageData.popValue(&passCard, sizeof(DZ_CMD_S_PassCard));
onSubPassCard(&passCard, sizeof(DZ_CMD_S_PassCard));
}
// 游戏结束;
else if (kAction.wSubCmdID == DZ_SUB_S_GAME_END)
{
DZ_CMD_S_GameConclude GameEnd;
zeromemory(&GameEnd, sizeof(GameEnd));
kAction.subMessageData.popValue(&GameEnd, sizeof(DZ_CMD_S_GameConclude));
onSubGameEnd(&GameEnd, sizeof(DZ_CMD_S_GameConclude));
}
m_iActRecordIdex++;
m_txtRecordPercent->setString(utility::toString(m_iActRecordIdex * 100 / m_GameRecord.actionVec.size(), "%"));
}
std::string DZGameScene::getGameRule(uint32 dwGameRule)
{
std::string strGameRule = "";
// 不带王规则;
if ((dwGameRule&eDZRuleEnum_NO_JOKER) > 0)
{
strGameRule += "不带王";
}
else
{
strGameRule += "带王";
}
if ((dwGameRule&eDZRuleEnum_MINGBIAN) > 0)
{
strGameRule += "、明边";
}
else
{
strGameRule += "、暗边";
}
if ((dwGameRule&eDZRuleEnum_TO_TWO) > 0)
{
strGameRule += "、只打二游";
}
if ((dwGameRule&eDZRuleEnum_NO_BOMB) > 0)
{
strGameRule += "、无炸摊牌";
}
if ((dwGameRule&eDZRuleEnum_EIGHT_BOMB) > 0)
{
strGameRule += "、八炸摊牌";
}
std::string strLotteryRule = "";
if ((dwGameRule&eDZRuleEnum_LOTTERY_7) > 0)
{
if (strLotteryRule.length() <= 0)
{
strLotteryRule = "开奖:";
}
strLotteryRule += "7";
}
if ((dwGameRule&eDZRuleEnum_LOTTERY_10) > 0)
{
if (strLotteryRule.length() <= 0)
{
strLotteryRule = "开奖:";
}
else
{
strLotteryRule += "";
}
strLotteryRule += "10";
}
if ((dwGameRule&eDZRuleEnum_LOTTERY_J) > 0)
{
if (strLotteryRule.length() <= 0)
{
strLotteryRule = "开奖:";
}
else
{
strLotteryRule += "";
}
strLotteryRule += "J";
}
if ((dwGameRule&eDZRuleEnum_LOTTERY_K) > 0)
{
if (strLotteryRule.length() <= 0)
{
strLotteryRule = "开奖:";
}
else
{
strLotteryRule += "";
}
strLotteryRule += "K";
}
std::string strAllInfo = "";
if (strLotteryRule.length() > 0)
{
strAllInfo = strGameRule + "" + strLotteryRule;
}
else
{
strAllInfo = strGameRule;
}
return strAllInfo;
}