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

2310 lines
59 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 "NN_GameScene.h"
#include "NN_GamePlayer.h"
#include "NN_GameLogic.h"
#include "UserInfo.h"
#include "MainScene.h"
#include "MissionWeiXin.h"
#include "DismissScene.h"
#include "NN_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"
using namespace NiuNiu_SPACE;
bool NNGameScene::init()
{
if (!GameFrameBase::init())
{
return false;
}
m_nVoiceTimeID = 0;
m_strGameRuleInfo = "";
_bCuoPai = false;
_bWin = false;
_lMinFreeChip = 0;
_lMaxFreeChip = 0;
zeromemory(&m_PrivateRoomInfo, sizeof(CMD_GF_Private_Room_Info));
initNet();
initScene();
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile("Games/NiuNiu/Table/oxnn_card.plist");
return true;
}
//进场动画完成回调;
void NNGameScene::onEnterTransitionDidFinish()
{
GameFrameBase::onEnterTransitionDidFinish();
if (true == GAME_MUISCBG)
{
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Games/NiuNiu/Audio/background.mp3", true);
}
// 暂时停了测试;
#if CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
pAudio->stopBackgroundMusic(true);
#endif
// 录像模式;
if (m_IsGameRecord)
{
StartRecord(NN_GAME_PLAYER);
}
else
{
// 增加游戏内事件处理;
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addCustomEventListener(SHOW_PRIVATE_END, CC_CALLBACK_1(NNGameScene::onEventShowPrivate, this));
CGameServerItem* pGameServerItem = GameMission::g_pGameServerItem;
CC_ASSERT(pGameServerItem != nullptr);
if (pGameServerItem != nullptr)
{
m_kGameMission.SetServerItem(pGameServerItem);
m_kGameMission.start();
}
}
}
//场景退出;
void NNGameScene::onExit()
{
GameFrameBase::onExit();
for (int i = 0; i < NN_GAME_PLAYER; i++)
{
SafeDelete(m_aryPlayer[i]);
}
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->removeCustomEventListeners(SHOW_PRIVATE_END);
}
//场景初始化;
void NNGameScene::initScene()
{
//根节点;
m_rootNode = CSLoader::createNodeWithVisibleSize("Games/NiuNiu/GameTableScene.csb");
CC_ASSERT(m_rootNode != nullptr);
this->addChild(m_rootNode, ZO_DEFAULT);
// 公告;
auto ImageSytem = (ImageView*)m_rootNode->getChildByName("ImgRoll");
CC_ASSERT(ImageSytem!=nullptr);
SetSystemNode(ImageSytem);
// 绑定界面元素;
_MainPanel = static_cast<Layout*>(m_rootNode->getChildByName("MainPanel"));
CC_ASSERT(_MainPanel != nullptr);
// 房间ID;
_txtRoomID = static_cast<TextBMFont*>(_MainPanel->getChildByName("txtRoomID"));
CC_ASSERT(_txtRoomID != nullptr);
// 房间规则;
_txtRoomRule = static_cast<Text*>(_MainPanel->getChildByName("txtRoomRule"));
CC_ASSERT(_txtRoomRule != nullptr);
//_spRoomRule1 = static_cast<Sprite*>(_MainPanel->getChildByName("spRoomRule1"));
//CC_ASSERT(_spRoomRule1 != nullptr);
// 局数;
_txtJushu = static_cast<TextBMFont*>(_MainPanel->getChildByName("txtRoundNum"));
CC_ASSERT(_txtJushu != nullptr);
_txtJushu->setVisible(false);
// 结束面板;
_ResultPanel = static_cast<Layout*>(_MainPanel->getChildByName("ResultPanel"));
CC_ASSERT(_ResultPanel != nullptr);
_ResultPanel->setVisible(false);
// 结束动画;
_pArmatureEnd = static_cast<Armature*>(_ResultPanel->getChildByName("ArmatureEnd"));
CC_ASSERT(_pArmatureEnd != nullptr);
_pArmatureEnd->setVisible(false);
ArmatureAnimation* pArmatureEnd = _pArmatureEnd->getAnimation();
if (pArmatureEnd != nullptr)
{
pArmatureEnd->setMovementEventCallFunc([=](cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID){
// 播放完成;
if ((movementType == cocostudio::COMPLETE) && ("win1" == movementID))
{
pArmatureEnd->play("win2", -1, 1);
}
else if ((movementType == cocostudio::COMPLETE) && ("lose1" == movementID))
{
pArmatureEnd->play("lose2", -1, 1);
}
});
}
// 继续按钮;
_btnContinue = static_cast<Button*>(_ResultPanel->getChildByName("btnContinue"));
CC_ASSERT(_btnContinue != nullptr);
// 旁边按钮;
_btnLookon = static_cast<Button*>(_ResultPanel->getChildByName("btnLookon"));
CC_ASSERT(_btnLookon != nullptr);
_btnLookon->setVisible(false);
// 按钮面板;
_ButtonPanel = static_cast<Button*>(_MainPanel->getChildByName("ButtonPanel"));
CC_ASSERT(_ButtonPanel != nullptr);
// 微信邀请按钮;
_btnWXInvite = static_cast<Button*>(_ButtonPanel->getChildByName("btnInvite"));
CC_ASSERT(_btnWXInvite != nullptr);
_btnWXInvite->setVisible(false);
// 解散房间按钮;
_btnWXDismiss = static_cast<Button*>(_ButtonPanel->getChildByName("btnDismiss"));
CC_ASSERT(_btnWXDismiss != nullptr);
_btnWXDismiss->setVisible(false);
// 离开按钮;
_btnLeave = static_cast<Button*>(_ButtonPanel->getChildByName("btnLeave"));
CC_ASSERT(_btnLeave != nullptr);
//设置按钮;
auto btnSetting = static_cast<Button*>(_ButtonPanel->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();
});
// 语音按钮;
_btnWXVoice = static_cast<Button*>(_ButtonPanel->getChildByName("btnVoice"));
CC_ASSERT(_btnWXVoice != nullptr);
_btnWXVoice->addTouchEventListener(CC_CALLBACK_2(NNGameScene::OnButtonVoiceTouched, this));
// 聊天按钮;
_btnWXChat = static_cast<Button*>(_ButtonPanel->getChildByName("btnChat"));
CC_ASSERT(_btnWXChat != nullptr);
_btnWXChat->addClickEventListener([this](Ref*){
YSAudioEngine::Instance().playBtnClickEffect();
const std::vector<std::string>& chatList = getShortChatList();
auto chatLayer = ChatLayer::create(chatList);
CC_ASSERT(chatLayer != nullptr);
this->addChild(chatLayer, ZO_ANI);
chatLayer->pushScene();
});
// 开始按钮;
_btnStartGame = static_cast<Button*>(_ButtonPanel->getChildByName("btnStartGame"));
CC_ASSERT(_btnStartGame != nullptr);
_btnStartGame->setVisible(false);
// 游戏面板;
_GamePanel = static_cast<Layout*>(_MainPanel->getChildByName("GamePanel"));
CC_ASSERT(_GamePanel != nullptr);
// 自动算牛按钮;
_btnAutoNiu = static_cast<Button*>(_GamePanel->getChildByName("btnAutoNiu"));
CC_ASSERT(_btnAutoNiu != nullptr);
_btnAutoNiu->setVisible(false);
// 搓牌按钮;
_btnCuoPai = static_cast<Button*>(_GamePanel->getChildByName("btnCuoPai"));
CC_ASSERT(_btnCuoPai != nullptr);
_btnCuoPai->setVisible(false);
// 抢庄面板;
_RobPanel = static_cast<Layout*>(_GamePanel->getChildByName("RobPanel"));
CC_ASSERT(_RobPanel != nullptr);
_RobPanel->setVisible(false);
// 不抢庄;
_btnRobNO = static_cast<Button*>(_RobPanel->getChildByName("btnRobNO"));
CC_ASSERT(_btnRobNO != nullptr);
// 抢庄;
_btnRobYES = static_cast<Button*>(_RobPanel->getChildByName("btnRobYES"));
CC_ASSERT(_btnRobYES != nullptr);
// 加注面板;
_YazhuPanel1 = static_cast<Layout*>(_GamePanel->getChildByName("YazhuPanel1"));
CC_ASSERT(_YazhuPanel1 != nullptr);
_YazhuPanel1->setVisible(false);
_spOtherCallBanker = static_cast<Sprite*>(_MainPanel->getChildByName("other_callBanker"));
CC_ASSERT(_spOtherCallBanker != nullptr);
_spOtherAddScore = static_cast<Sprite*>(_MainPanel->getChildByName("other_addScore"));
CC_ASSERT(_spOtherAddScore != nullptr);
_spSelfAddScore = static_cast<Sprite*>(_MainPanel->getChildByName("self_addScore"));
CC_ASSERT(_spSelfAddScore != nullptr);
setOperateStatus(NN_OS_NULL);
// 时钟精灵;
_imgGameClock = static_cast<Sprite*>(_MainPanel->getChildByName("imgGameClock"));
CC_ASSERT(_imgGameClock != nullptr);
_imgGameClock->setVisible(false);
// 筹码面板;
_ChipPanel = static_cast<Layout*>(_MainPanel->getChildByName("ChipPanel"));
CC_ASSERT(_ChipPanel != nullptr);
// 发牌位置;
_ptSendCardPos = _MainPanel->getChildByName("imgCard")->getPosition();
// 语音标志;
m_pVoiceNode = (Node*)m_rootNode->getChildByName("VoiceNode");
CC_ASSERT(m_pVoiceNode != nullptr);
m_pVoiceNode->setVisible(false);
for (int i = 0; i < NN_GAME_PLAYER; i++)
{
std::string strName = StringUtils::format("panelChair_%d", i);
Layout* layout = static_cast<Layout*>(_MainPanel->getChildByName(strName));
CC_ASSERT(layout!=nullptr);
m_aryPlayer[i] = new NN_GamePlayer(i, layout);
layout->addClickEventListener([i, this](Ref* pSender){
CC_ASSERT(pSender != nullptr);
if (nullptr == pSender) return;
YSAudioEngine::Instance().playBtnClickEffect();
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[NN_VIEW_SELF_ID];
// 开始动画;
_pArmatureStart = (Armature*)_MainPanel->getChildByName("ArmatureStart");
CC_ASSERT(_pArmatureStart != nullptr);
_pArmatureStart->setVisible(false);
ArmatureAnimation* pArmatureStart = _pArmatureStart->getAnimation();
if (pArmatureStart != nullptr)
{
pArmatureStart->setMovementEventCallFunc([=](cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID){
// 播放完成;
if ((movementType == cocostudio::COMPLETE) && ("NNGameStart" == movementID))
{
// 发牌动画;
float fDelayTime = playSendCardAni();
uint8 cbUserStatus = m_pLocalPlayer->GetUserStatus();
if (cbUserStatus == US_PLAYING)
{
auto callback = [=]() {
sendSendCardOverMsg();
};
runAction(Sequence::create(DelayTime::create(fDelayTime), CallFunc::create(callback), nullptr));
}
_pArmatureStart->setVisible(false);
}
});
}
// 退出回调;
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);
};
_btnStartGame->addClickEventListener([=](Ref* pSender) {
// 开始游戏;
playBtnClickEffect();
SendUserReady();
_btnStartGame->setEnabled(false);
});
_btnWXInvite->addClickEventListener([=](Ref* pSender) {
// 邀请;
playBtnClickEffect();
//std::string strGameTitle = StringUtils::format("%s[房号:%d]", strNickName.c_str(), m_PrivateRoomInfo.dwRoomNum);
std::string strUrl = GlobalJosn::getInstance()->getShareInfoByKind(SH_KIND_WEIXIN_URL);
std::string strUrlInfo = StringUtils::format("%s?param=%d", strUrl.c_str(), m_PrivateRoomInfo.dwRoomNum);
std::string strRoomID = StringUtils::format("房间号(%d), ", m_PrivateRoomInfo.dwRoomNum);
std::string strShareRule = strRoomID + m_strGameRuleInfo + StringUtils::format("人数: %d/%d", getCurPlayerCount(), NN_GAME_PLAYER);
MissionWeiXin::Instance().shareUrlWeiXin(strUrlInfo, m_strGameTitle, strShareRule);
//SelectShareScene::Instance().shareRoomInfo(strUrlInfo, utility::a_u8(m_strGameTitle), strShareRule, 0);
});
// 解散房间函数;
auto callback = [this](){
onEventAgreeDismissRoom(true);
};
_btnWXDismiss->addClickEventListener([=](Ref* pSender) {
// 解散;
playBtnClickEffect();
std::string strTip;
if (0 == m_PrivateRoomInfo.dwPlayCout && false == m_PrivateRoomInfo.bStartGame)
{
strTip = "牌局开始前解散房间不扣房卡,是否解散?";
}
else
{
strTip = "您确定要解散房间吗?";
}
PopScene::Instance().show(utility::a_u8(strTip.c_str()), callback, nullptr);
});
// 离开按钮
_btnLeave->addClickEventListener([=](Ref* pSender){
YSAudioEngine::Instance().playBtnClickEffect();
GamePlayer* pGamePlayer = getSelfGamePlayer();
auto callback_ok = [=](){
if (pGamePlayer != nullptr)
{
CMD_GR_UserStandUp request;
memset(&request, 0, sizeof(request));
request.wTableID = pGamePlayer->GetTableID();
request.wChairID = pGamePlayer->GetChairID();
request.cbForceLeave = true;
m_kGameMission.SendSocketData(MDM_GR_USER, SUB_GR_USER_STANDUP, &request, sizeof(request));
}
this->runAction(Sequence::createWithTwoActions(DelayTime::create(0.2f), CallFunc::create([=]{
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(LEAVE_GAME);
})));
};
std::string strPop = "您确定要离开房间吗?";
if (m_cbGameStatus != NN_GS_TK_FREE)
{
strPop = "您正在游戏中,强行退出会被扣分,确定要强退吗?";
}
PopScene::Instance().show(utility::a_u8(strPop), callback_ok, nullptr);
});
// 加注;
for (int i = 1; i <= 5; i++)
{
std::string strName = StringUtils::format("btnYazhu%d", i);
auto btnYazhu = static_cast<Button*>(_YazhuPanel1->getChildByName(strName));
CC_ASSERT(btnYazhu!=nullptr);
btnYazhu->addClickEventListener([=](Ref* pSender) {
Button* pBtn = (Button*)pSender;
playBtnClickEffect();
operateAction(pBtn->getName());
});
}
// 不抢庄;
_btnRobNO->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
operateAction("RobNO");
});
// 抢庄;
_btnRobYES->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
operateAction("RobYES");
});
// 搓牌;
_btnCuoPai->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
operateAction("TiShi");
});
// 自动算牛;
_btnAutoNiu->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
operateAction("LiangPai");
});
// 查看结算;
_btnLookon->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
_OpenResultScene->setVisible(true);
});
// 继续游戏;
_btnContinue->addClickEventListener([=](Ref* pSender) {
playBtnClickEffect();
SendUserReady();
_ResultPanel->setVisible(false);
});
// 私人场结束面板;
_OpenResultScene = NNPrivateEndNode::create();
addChild(_OpenResultScene);
_OpenResultScene->setVisible(false);
//对手机返回键的监听 ;
auto keyListener = EventListenerKeyboard::create();
//和回调函数绑定 ;
keyListener->onKeyReleased = [=](EventKeyboard::KeyCode keyCode, Event * pEvent){
//返回值处理;
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
{
#if CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM
if (m_kGameMission.isAlive())
{
m_kGameMission.stop();
}
else
{
this->ReconnectServer();
}
return;
#endif
exitCallFunc(nullptr);
}
};
//添加到事件分发器中 ;
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
loadShortChat("Games/DDZ/ShortChat/ChatInfo.json");
//重置场景;
resetScene();
//重置数据;
ResetAllData();
}
void NNGameScene::onSliderEventCallback(Ref* widget, Slider::EventType type)
{
//Slider* slider = (Slider*)widget;
//if (type == Slider::EventType::ON_SLIDEBALL_DOWN)
//{
// cocos2d::log("slider button pressed!");
//}
//else if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
//{
// cocos2d::log("slider is moving! percent = %f", 100.0f * slider->getPercent() / slider->getMaxPercent());
// int iPercent = slider->getPercent();
// float minPercent = _lMinFreeChip * 100 / _lMaxFreeChip;
// if (iPercent < minPercent)
// {
// _sliderJiaZhu->setPercent(minPercent);
// _txtZhu->setString(StringUtils::format("%d", _lMinFreeChip));
// _lAddChip = _lMinFreeChip;
// return;
// }
// int addChip = iPercent * _lMaxFreeChip / 100;
// _txtZhu->setString(StringUtils::format("%d", addChip));
// _lAddChip = addChip;
//}
//else if (type == Slider::EventType::ON_SLIDEBALL_UP)
//{
// cocos2d::log("slider button is released.");
//}
}
//重置场景;
void NNGameScene::resetScene(bool bAll/* = false*/)
{
setOperateStatus(NN_OS_NULL);
closeGameClock();
//重置玩家UI;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
m_aryPlayer[i]->resetUI(bAll);
}
}
//重置数据;
void NNGameScene::resetData()
{
m_cbGameStatus = NN_GS_TK_FREE;
_iBaseScore = 0;
_wLordUser = INVALID_CHAIR;
_wCurrentUser = INVALID_CHAIR;
_cbHandCardCount = NN_MAX_COUNT;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryRobStatus[i] = 0;
_aryChipStatus[i] = 0;
_aryOpenStatus[i] = 0;
_aryActiveStatus[i] = false;
_aryCardNiuType[i] = -1;
_aryTableScore[i] = 0;
}
zeromemory(_lViewGameScore, sizeof(_lViewGameScore));
zeromemory(_aryHandCardData, sizeof(_aryHandCardData));
zeromemory(_aryAllHandCardData, sizeof(_aryAllHandCardData));
vector<Sprite*>::iterator iter = _aryChipSprite.begin();
for (; iter != _aryChipSprite.end(); iter++)
{
Sprite* pSpr = (Sprite*)*iter;
if (pSpr != nullptr)
{
pSpr->removeFromParent();
}
}
_aryChipSprite.clear();
}
//重置数据(相当于玩家离开);
void NNGameScene::ResetAllData()
{
resetScene();
resetData();
}
//重置桌子;
void NNGameScene::ResetTable()
{
resetScene(true);
resetData();
}
//获取快捷语音文件路径;
const std::string NNGameScene::getShortChatSoundPath(uint8 cbGender, int nIndex)
{
// 短语;
std::string strFilePath = "Games/DDZ/ShortChat/";
if (cbGender == enMan)
{
strFilePath += StringUtils::format("man/%d.mp3", nIndex);
}
else
{
strFilePath += StringUtils::format("woman/%d.mp3", nIndex);
}
return strFilePath;
}
//绑定网络消息;
void NNGameScene::initNet()
{
addNetCBDefine(NN_SUB_S_GAME_START, this, NNGameScene::onSubGameStart);
addNetCBDefine(NN_SUB_S_START_ROB, this, NNGameScene::onSubStartRob);
addNetCBDefine(NN_SUB_S_USER_ROB, this, NNGameScene::onSubUserRob);
addNetCBDefine(NN_SUB_S_START_CHIP, this, NNGameScene::onSubStartChip);
addNetCBDefine(NN_SUB_S_USER_CHIP, this, NNGameScene::onSubUserChip);
addNetCBDefine(NN_SUB_S_START_OPEN, this, NNGameScene::onSubStartOpen);
addNetCBDefine(NN_SUB_S_OPEN_CARD, this, NNGameScene::onSubOpenCard);
addNetCBDefine(NN_SUB_S_GAME_END, this, NNGameScene::onSubGameEnd);
addNetCBDefine(NN_SUB_S_ALL_OPEN_CARD, this, NNGameScene::onSubAllOpenCard);
}
bool NNGameScene::OnEventSceneMessage(uint8 cbGameStatus, bool bLookonUser, void* pData, int nDataSize)
{
m_cbGameStatus = cbGameStatus;
switch (cbGameStatus)
{
case NN_GS_TK_FREE:
{
return onGameSceneFree(pData, nDataSize);
}
case NN_GS_TK_SEND_CARD:
{
return onGameSceneSendCard(pData, nDataSize);
}
case NN_GS_TK_ROB_BANKER:
{
return onGameSceneRomBanker(pData, nDataSize);
}
case NN_GS_TK_USER_CHIP:
{
return onGameSceneUserChip(pData, nDataSize);
}
case NN_GS_TK_OPEN_CARD:
{
return onGameSceneOpenCard(pData, nDataSize);
}
case NN_GS_TK_SHOW_CARD:
{
return onGameSceneEnd(pData, nDataSize);
}
default:
break;
}
return true;
}
//恢复空闭场景;
bool NNGameScene::onGameSceneFree(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusFree));
NN_CMD_S_StatusFree* pStatusFree = (NN_CMD_S_StatusFree*)pData;
_lMinFreeChip = pStatusFree->lMinFreeChip;
_lMaxFreeChip = pStatusFree->lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusFree->bActiveStatus[i];
}
return true;
}
//恢复发牌场景;
bool NNGameScene::onGameSceneSendCard(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusSend));
NN_CMD_S_StatusSend* pStatusSend = (NN_CMD_S_StatusSend*)pData;
_lMinFreeChip = pStatusSend->stStatusFree.lMinFreeChip;
_lMaxFreeChip = pStatusSend->stStatusFree.lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusSend->stStatusFree.bActiveStatus[i];
}
_wLordUser = pStatusSend->wBankerUser;
memcpy(_aryHandCardData, pStatusSend->cbHandCardData, sizeof(_aryHandCardData));
uint16 wMyChairID = getSelfChairID();
CC_ASSERT(wMyChairID<NN_GAME_PLAYER);
if (wMyChairID<NN_GAME_PLAYER)
{
memcpy(_aryAllHandCardData[wMyChairID], pStatusSend->cbHandCardData, sizeof(pStatusSend->cbHandCardData));
}
showLordUser();
showPlayerCard();
uint8 cbUserStatus = m_pLocalPlayer->GetUserStatus();
if (1 == pStatusSend->cbSendStatus && cbUserStatus == US_PLAYING)
{
sendSendCardOverMsg();
}
return true;
}
//抢庄状态;
bool NNGameScene::onGameSceneRomBanker(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusRob));
NN_CMD_S_StatusRob* pStatusRob = (NN_CMD_S_StatusRob*)pData;
setOperateStatus(NN_OS_CALLBANK);
_lMinFreeChip = pStatusRob->stStatusFree.lMinFreeChip;
_lMaxFreeChip = pStatusRob->stStatusFree.lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusRob->stStatusFree.bActiveStatus[i];
_aryRobStatus[i] = pStatusRob->cbRobStatus[i];
}
memcpy(_aryAllHandCardData, pStatusRob->cbHandCardData, sizeof(_aryAllHandCardData));
uint16 wMyChairID = getSelfChairID();
CC_ASSERT(wMyChairID < NN_GAME_PLAYER);
if (wMyChairID < NN_GAME_PLAYER)
{
memcpy(_aryHandCardData, _aryAllHandCardData[wMyChairID], sizeof(_aryHandCardData));
}
log("onStatusRobLordEvent-");
showPlayerCard();
uint16 wSelfChairID = getSelfChairID();
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
if (_aryActiveStatus[i] && pStatusRob->cbRobStatus[i] == 2)
{
uint16 wViewID = SwitchViewChairID(i);
log("onStatusRobLordEvent -%d %d", wViewID, i);
m_aryPlayer[wViewID]->setRobIconVisible(true);
}
}
if (_aryActiveStatus[wSelfChairID] && pStatusRob->cbRobStatus[wSelfChairID] == 0)
{
log("_RobPanel");
_RobPanel->setVisible(true);
}
openGameClock(NN_OPEN_CARD_TIME);
return true;
}
//下注状态;
bool NNGameScene::onGameSceneUserChip(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusChip));
NN_CMD_S_StatusChip* pStatusChip = (NN_CMD_S_StatusChip*)pData;
_lMinFreeChip = pStatusChip->stStatusFree.lMinFreeChip;
_lMaxFreeChip = pStatusChip->stStatusFree.lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusChip->stStatusFree.bActiveStatus[i];
_aryChipStatus[i] = pStatusChip->cbChipStatus[i];
}
memcpy(_aryHandCardData, pStatusChip->cbHandCardData, sizeof(_aryHandCardData));
uint16 wMyChairID = getSelfChairID();
CC_ASSERT(wMyChairID < NN_GAME_PLAYER);
if (wMyChairID < NN_GAME_PLAYER)
{
memcpy(_aryAllHandCardData[wMyChairID], pStatusChip->cbHandCardData, sizeof(pStatusChip->cbHandCardData));
}
_wLordUser = pStatusChip->wBankerUser;
showLordUser();
showPlayerCard();
uint16 wSelfChairID = getSelfChairID();
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
if (_aryActiveStatus[i] && pStatusChip->cbChipStatus[i] == 1)
{
uint16 wViewID = SwitchViewChairID(i);
//playChipAni(wViewID, pStatusChip->lUserChipScore[i], true);
//ShowGoldMoveToArea(pStatusChip->lUserChipScore[i], wViewID);
m_aryPlayer[wViewID]->updateUserChip(pStatusChip->lUserChipScore[i]);
}
}
if (wSelfChairID != _wLordUser && _aryActiveStatus[wSelfChairID] && pStatusChip->cbChipStatus[wSelfChairID] == 0)
{
_YazhuPanel1->setVisible(true);
setOperateStatus(NN_OS_ADDSCORE1);
}
else
{
setOperateStatus(NN_OS_ADDSCORE0);
}
playEffect("addScroe");
openGameClock(NN_OPEN_CARD_TIME);
return true;
}
//开牌状态;
bool NNGameScene::onGameSceneOpenCard(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusOpen));
NN_CMD_S_StatusOpen* pStatusOpen = (NN_CMD_S_StatusOpen*)pData;
_lMinFreeChip = pStatusOpen->stStatusFree.lMinFreeChip;
_lMaxFreeChip = pStatusOpen->stStatusFree.lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusOpen->stStatusFree.bActiveStatus[i];
//_aryCardNiuType[i] = pStatusOpen->cbHandCardType[i];
_aryOpenStatus[i] = pStatusOpen->cbOpenStatus[i];
}
//memcpy(_aryAllHandCardData, pStatusOpen->cbHandCardData, sizeof(_aryAllHandCardData));
// 自己手牌控制;
uint16 wMyChairID = getSelfChairID();
CC_ASSERT(wMyChairID < NN_GAME_PLAYER);
if (wMyChairID < NN_GAME_PLAYER)
{
memcpy(_aryAllHandCardData[wMyChairID], pStatusOpen->cbHandCardData, sizeof(pStatusOpen->cbHandCardData));
memcpy(_aryHandCardData, _aryAllHandCardData[wMyChairID], sizeof(_aryHandCardData));
}
_wLordUser = pStatusOpen->wBankerUser;
showLordUser();
//showPlayerCard();
uint16 wSelfChairID = getSelfChairID();
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
if (_aryActiveStatus[i])
{
uint16 wViewID = SwitchViewChairID(i);
if (_wLordUser != i)
{
m_aryPlayer[wViewID]->updateUserChip(pStatusOpen->lUserChipScore[i]);
}
// 自己显示;
if (i == wSelfChairID)
{
if (0 == pStatusOpen->cbOpenStatus[i])
{
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT);
}
else
{
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT, pStatusOpen->cbHandCardType);
}
}
else
{
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT);
}
//// 没开牌;
//if (0 == pStatusOpen->cbOpenStatus[i])
//{
// m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT);
//}
//else
//{
// m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT, pStatusOpen->cbHandCardType[i]);
//}
}
}
if (_aryActiveStatus[wSelfChairID] && pStatusOpen->cbOpenStatus[wSelfChairID] == 0)
{
// 我没开;
_btnCuoPai->setVisible(true);
_btnAutoNiu->setVisible(true);
}
else
{
//_txtTanpai->setString(utility::a_u8("等待其他玩家开牌..."));
_btnCuoPai->setVisible(false);
_btnAutoNiu->setVisible(false);
setOperateStatus(NN_OS_NULL);
}
openGameClock(NN_OPEN_CARD_TIME);
return true;
}
//游戏结束;
bool NNGameScene::onGameSceneEnd(void* pData, int nDataSize)
{
//校验数据;
CC_ASSERT(nDataSize == sizeof(NN_CMD_S_StatusAllOpen));
NN_CMD_S_StatusAllOpen* pStatusOpen = (NN_CMD_S_StatusAllOpen*)pData;
_lMinFreeChip = pStatusOpen->stStatusFree.lMinFreeChip;
_lMaxFreeChip = pStatusOpen->stStatusFree.lMaxFreeChip;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pStatusOpen->stStatusFree.bActiveStatus[i];
_aryCardNiuType[i] = pStatusOpen->cbHandCardType[i];
_aryOpenStatus[i] = pStatusOpen->cbOpenStatus[i];
}
memcpy(_aryAllHandCardData, pStatusOpen->cbHandCardData, sizeof(_aryAllHandCardData));
uint16 wMyChairID = getSelfChairID();
CC_ASSERT(wMyChairID < NN_GAME_PLAYER);
if (wMyChairID < NN_GAME_PLAYER)
{
memcpy(_aryHandCardData, _aryAllHandCardData[wMyChairID], sizeof(_aryHandCardData));
}
_wLordUser = pStatusOpen->wBankerUser;
showLordUser();
uint16 wSelfChairID = getSelfChairID();
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
if (_aryActiveStatus[i])
{
uint16 wViewID = SwitchViewChairID(i);
if (_wLordUser != i)
{
m_aryPlayer[wViewID]->updateUserChip(pStatusOpen->lUserChipScore[i]);
}
// 没开牌;
if (0 == pStatusOpen->cbOpenStatus[i])
{
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT);
}
else
{
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT, pStatusOpen->cbHandCardType[i]);
}
}
}
_btnCuoPai->setVisible(false);
_btnAutoNiu->setVisible(false);
setOperateStatus(NN_OS_NULL);
return true;
}
void NNGameScene::onSubGameStart(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_GameStart));
NN_CMD_S_GameStart* pGameStart = (NN_CMD_S_GameStart*)pBuffer;
ResetAllData();
_wLordUser = pGameStart->wBankerUser;
memcpy(_aryHandCardData, pGameStart->cbHandCardData, sizeof(_aryHandCardData));
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
_aryActiveStatus[i] = pGameStart->bActiveStatus[i];
}
showLordUser(true); // 显示庄家;
// 开局动画;
ArmatureAnimation* pArmature = _pArmatureStart->getAnimation();
if (pArmature != nullptr)
{
_pArmatureStart->setVisible(true);
pArmature->play("NNGameStart", -1, 0);
}
else
{
// 发牌动画;
float fDelayTime = playSendCardAni();
uint8 cbUserStatus = m_pLocalPlayer->GetUserStatus();
if (cbUserStatus == US_PLAYING)
{
auto callback = [=]() {
sendSendCardOverMsg();
};
runAction(Sequence::create(DelayTime::create(fDelayTime), CallFunc::create(callback), nullptr));
}
}
}
//开始抢庄;
void NNGameScene::onSubStartRob(const void * pBuffer, uint16 wDataSize)
{
uint16 wSelfChairID = getSelfChairID();
CC_ASSERT(wSelfChairID<NN_GAME_PLAYER);
if (_aryActiveStatus[wSelfChairID])
{
_RobPanel->setVisible(true);
}
setOperateStatus(NN_OS_CALLBANK);
openGameClock(NN_OPEN_CARD_TIME);
}
//玩家抢庄;
void NNGameScene::onSubUserRob(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_UserRob));
NN_CMD_S_UserRob* pUserRob = (NN_CMD_S_UserRob*)pBuffer;
uint16 wViewID = SwitchViewChairID(pUserRob->wRobUser);
CC_ASSERT(wViewID<NN_GAME_PLAYER);
m_aryPlayer[wViewID]->setRobIconVisible(pUserRob->bRobResult);
// 声音;
GamePlayer* player = getPlayerByChairID(pUserRob->wRobUser);
std::string strRobResult = StringUtils::format("%s", pUserRob->bRobResult ? "Qiangzhuan" : "Buqiang");
std::string strSound = StringUtils::format("woman/%s", strRobResult.c_str());
if (player->GetGender() == enMan)
{
strSound = StringUtils::format("man/%s", strRobResult.c_str());
}
playEffect(strSound);
}
//开始下注;
void NNGameScene::onSubStartChip(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_StartChip));
NN_CMD_S_StartChip* pStartChip = (NN_CMD_S_StartChip*)pBuffer;
_wLordUser = pStartChip->wBankerUser;
_RobPanel->setVisible(false);
showLordUser(true);
clearRobIcon();
uint16 wSelfChairID = getSelfChairID();
CC_ASSERT(wSelfChairID<NN_GAME_PLAYER);
if (wSelfChairID != _wLordUser && _aryActiveStatus[wSelfChairID])
{
_YazhuPanel1->setVisible(true);
setOperateStatus(NN_OS_ADDSCORE1);
}
else
{
setOperateStatus(NN_OS_ADDSCORE0);
}
playEffect("addScroe");
openGameClock(NN_OPEN_CARD_TIME);
}
//玩家下注;
void NNGameScene::onSubUserChip(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_UserChip));
NN_CMD_S_UserChip* pUserChip = (NN_CMD_S_UserChip*)pBuffer;
uint16 wViewID = SwitchViewChairID(pUserChip->wChipUser);
CC_ASSERT(wViewID<NN_GAME_PLAYER);
//playChipAni(wViewID, pUserChip->lChipScore, true);
//ShowGoldMoveToArea(pUserChip->lChipScore, wViewID);
m_aryPlayer[wViewID]->updateUserChip(pUserChip->lChipScore);
// 声音;
GamePlayer* player = getPlayerByChairID(pUserChip->wChipUser);
std::string strSound = StringUtils::format("woman/Chip%d", pUserChip->lChipScore);
if (player->GetGender() == enMan)
{
strSound = StringUtils::format("man/Chip%d", pUserChip->lChipScore);
}
playEffect(strSound);
// 如果是自已加注则隐藏加注面板;
if (wViewID==NN_VIEW_SELF_ID)
{
_YazhuPanel1->setVisible(false);
//_YazhuPanel2->setVisible(false);
setOperateStatus(NN_OS_ADDSCORE1);
}
}
//开始开牌;
void NNGameScene::onSubStartOpen(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_OpenCard));
NN_CMD_S_OpenCard* pOpenCard = (NN_CMD_S_OpenCard*)pBuffer;
setOperateStatus(NN_OS_NULL);
uint16 wSelfChairID = getSelfChairID();
CC_ASSERT(wSelfChairID<NN_GAME_PLAYER);
if (pOpenCard->wOpenUser == wSelfChairID)
{
memcpy(_aryHandCardData, pOpenCard->cbCardData, sizeof(_aryHandCardData));
uint16 wViewID = SwitchViewChairID(pOpenCard->wOpenUser);
CC_ASSERT(wViewID < NN_GAME_PLAYER);
m_aryPlayer[wViewID]->showCard(pOpenCard->cbCardData, NN_MAX_COUNT);
if (_aryActiveStatus[wSelfChairID])
{
_btnAutoNiu->setVisible(false);
_btnCuoPai->setVisible(true);
}
}
openGameClock(NN_OPEN_CARD_TIME);
}
//玩家开牌;
void NNGameScene::onSubOpenCard(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_OpenCard));
NN_CMD_S_OpenCard* pOpenCard = (NN_CMD_S_OpenCard*)pBuffer;
uint16 wViewID = SwitchViewChairID(pOpenCard->wOpenUser);
CC_ASSERT(wViewID<NN_GAME_PLAYER);
//m_aryPlayer[wViewID]->showCard(pOpenCard->cbCardData, NN_MAX_COUNT, pOpenCard->cbCardType);
uint16 wSelfChairID = getSelfChairID();
bool bSound = true;
if (pOpenCard->wOpenUser == wSelfChairID)
{
m_aryPlayer[wViewID]->showCard(pOpenCard->cbCardData, NN_MAX_COUNT, pOpenCard->cbCardType);
// 声音;
GamePlayer* player = getPlayerByChairID(pOpenCard->wOpenUser);
std::string strSound = StringUtils::format("woman/OX_%d", pOpenCard->cbCardType);
if (player->GetGender() == enMan)
{
strSound = StringUtils::format("man/OX_%d", pOpenCard->cbCardType);
}
playEffect(strSound);
setOperateStatus(NN_OS_NULL);
_btnAutoNiu->setVisible(false);
_btnCuoPai->setVisible(false);
closeGameClock();
}
//if (bSound)
//{
// // 声音;
// GamePlayer* player = getPlayerByChairID(pOpenCard->wOpenUser);
// std::string strSound = StringUtils::format("woman/OX_%d", pOpenCard->cbCardType);
// if (player->GetGender() == enMan)
// {
// strSound = StringUtils::format("man/OX_%d", pOpenCard->cbCardType);
// }
// playEffect(strSound);
//}
}
//游戏结束;
void NNGameScene::onSubGameEnd(const void * pBuffer, uint16 wDataSize)
{
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_GameEnd));
NN_CMD_S_GameEnd* pGameEnd = (NN_CMD_S_GameEnd*)pBuffer;
m_cbGameStatus = NN_GS_TK_FREE;
//_txtTanpai->setString("");
closeGameClock();
setOperateStatus(NN_OS_NULL);
_btnCuoPai->setVisible(false);
_btnAutoNiu->setVisible(false);
if (_ResultPanel != nullptr)
{
uint16 wLordUserViewID = SwitchViewChairID(_wLordUser);
// 玩家积分;
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
uint16 wViewID = SwitchViewChairID(i);
std::string strScoreKey = StringUtils::format("txtScore_%d", wViewID);
auto txtScore = (TextAtlas*)_ResultPanel->getChildByName(strScoreKey);
txtScore->setVisible(_aryActiveStatus[i]);
// 设置积分;
if (_aryActiveStatus[i])
{
SCORE lGameScore = pGameEnd->lGameScore[i];
if (lGameScore >= 0)
{
txtScore->setProperty(StringUtils::format(".%d", lGameScore),"Games/NiuNiu/Table/num_win.png", 38, 55, ".");
}
else
{
txtScore->setProperty(StringUtils::format("/%d", std::abs(lGameScore)), "Games/NiuNiu/Table/num_loss.png", 38, 55, ".");
}
}
}
uint16 wSelfChairID = getSelfChairID();
cocostudio::ArmatureAnimation* pArmature = _pArmatureEnd->getAnimation();
if (pGameEnd->lGameScore[wSelfChairID] <= 0)
{
if (pArmature != nullptr)
{
pArmature->play("lose1", -1, 0);
_pArmatureEnd->setVisible(true);
}
playEffect("lose");
}
else
{
if (pArmature != nullptr)
{
pArmature->play("win1", -1, 0);
_pArmatureEnd->setVisible(true);
}
playEffect("finalWin");
}
_ResultPanel->setVisible(true);
}
}
//所有玩家开牌;
void NNGameScene::onSubAllOpenCard(const void * pBuffer, uint16 wDataSize)
{
closeGameClock();
//校验数据;
CC_ASSERT(wDataSize == sizeof(NN_CMD_S_AllOpenCard));
NN_CMD_S_AllOpenCard* pAllOpenCard = (NN_CMD_S_AllOpenCard*)pBuffer;
uint16 wSelfChairID = getSelfChairID();
for (uint8 i = 0; i < NN_GAME_PLAYER; i++)
{
if (!pAllOpenCard->bActiveStatus[i]) continue;
uint16 wViewID = SwitchViewChairID(i);
m_aryPlayer[wViewID]->showCard(pAllOpenCard->cbHandCardData[i], NN_MAX_COUNT, pAllOpenCard->cbCardType[i]);
// 声音;
GamePlayer* player = getPlayerByChairID(i);
std::string strSound = StringUtils::format("woman/OX_%d", pAllOpenCard->cbCardType[i]);
if (player->GetGender() == enMan)
{
strSound = StringUtils::format("man/OX_%d", pAllOpenCard->cbCardType[i]);
}
playEffect(strSound);
if (i == wSelfChairID)
{
setOperateStatus(NN_OS_NULL);
_btnAutoNiu->setVisible(false);
_btnCuoPai->setVisible(false);
}
}
}
//用户进入;
void NNGameScene::OnEventUserEnter(GamePlayer * pPlayer)
{
if (pPlayer == nullptr) return;
uint8 cbUserStatus = pPlayer->GetUserStatus();
if (pPlayer->GetChairID() == getSelfChairID())
{
//更新准备按钮状态;
if (cbUserStatus >= US_READY || m_cbGameStatus>NN_GS_TK_FREE)
{
//_btnStartGame->setVisible(false);
_btnStartGame->setEnabled(false);
_ResultPanel->setVisible(false);
}
else
{
//_btnStartGame->setVisible(true);
}
}
if (cbUserStatus == US_READY)
{
// 声音;
std::string strSound = "woman/ready";
if (pPlayer->GetGender() == enMan)
{
strSound = "man/ready";
}
playEffect(strSound);
}
}
//玩家状态改变;
void NNGameScene::OnEventUserStatus(GamePlayer * pPlayer)
{
OnEventUserEnter(pPlayer);
}
// 玩家离开;
void NNGameScene::OnEventUserLeave(GamePlayer * pPlayer)
{
if (pPlayer == nullptr) return;
cocos2d::log(a_u8c("用户%s 离开, 用户ID%d."), pPlayer->GetNickName().c_str(), pPlayer->GetUserID());
}
// 发牌动画;
float NNGameScene::playSendCardAni()
{
playSendCardEffect();
float fDelaySendTime = 0.1f;
for (int i = 0; i < _cbHandCardCount; i++)
{
for (int j = 0; j< NN_GAME_PLAYER; j++)
{
if (_aryActiveStatus[j])
{
std::string strName = StringUtils::format("SendCardSprite%d", j);
auto pCardSprite = Sprite::createWithSpriteFrameName("oxnn_card_back.png");
pCardSprite->setAnchorPoint(Vec2(0.5f, 0.5f));
pCardSprite->setScale(0.6f);
pCardSprite->setTag(j * 10 + i);
pCardSprite->setName(strName);
pCardSprite->setPosition(_ptSendCardPos);
_MainPanel->addChild(pCardSprite);
uint16 wViewID = SwitchViewChairID(j);
CC_ASSERT(wViewID<NN_GAME_PLAYER);
if (wViewID<NN_GAME_PLAYER)
{
moveSentCardSprite(pCardSprite, wViewID, fDelaySendTime);
}
fDelaySendTime = fDelaySendTime + 0.1f;
}
}
}
return fDelaySendTime;
}
void NNGameScene::moveSentCardSprite(Sprite* pCardSprite, uint16 wViewID, float fDelayTime)
{
CC_ASSERT(wViewID<NN_GAME_PLAYER);
int nTag = pCardSprite->getTag();
uint16 wChairID = nTag / 10;
uint8 cbIndex = nTag % 10;
const Vec2 ptCardPos = m_aryPlayer[wViewID]->getHandCardPos(cbIndex);
log("wViewID = %d, cbInde = %d, x = %f, y = %f", wViewID, cbIndex, ptCardPos.x, ptCardPos.y);
Vec2 ptEndPos = ptCardPos;
auto pAction = Spawn::create(MoveTo::create(0.1f, ptEndPos), RotateBy::create(0.2f, 360), nullptr);
auto callback = [=](Node* pNode) {
// 替换真牌;
uint8 cbCardData = 0;
if (wChairID==getSelfChairID())
{
cbCardData = _aryHandCardData[cbIndex];
}
m_aryPlayer[wViewID]->addCard(cbCardData, cbIndex);
pNode->removeFromParent();
};
pCardSprite->runAction(Sequence::create(DelayTime::create(fDelayTime), pAction, CallFuncN::create(callback), nullptr));
}
// 扔筹码动画;
void NNGameScene::playChipAni(uint16 wViewID, int nCount, bool bAction)
{
playEffect("jiaEffect");
// 临时筹码精灵数组;
const Vec2 ptHeadPos = m_aryPlayer[wViewID]->getHeadPos();
float startPosX = ptHeadPos.x - _ChipPanel->getPositionX();
float startPosY = ptHeadPos.y - _ChipPanel->getPositionY();
auto pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile("Games/NiuNiu/Table/PinChip.plist");
// 显示筹码数字;
int aryChipGroup[5] = { 5, 4, 3, 2, 1 };
for (int i = 0; i< 5; i++)
{
int nNum = nCount / aryChipGroup[i];
if (nNum > 0)
{
auto chipStr = StringUtils::format("imgChip%d.png", aryChipGroup[i]);
for (int k = 0; k<nNum; k++)
{
auto sp = Sprite::createWithSpriteFrameName(chipStr);
sp->setScale(0.7f);
float spW = sp->getContentSize().width * 0.7f;
float spH = sp->getContentSize().height * 0.7f;
_ChipPanel->addChild(sp);
float endPosX = (spW / 2) + (_ChipPanel->getContentSize().width - spW)*cocos2d::rand_0_1();
float endPosY = (spH / 2) + (_ChipPanel->getContentSize().height - spH)*cocos2d::rand_0_1();
if (bAction)
{
sp->setPosition(Vec2(startPosX, startPosY));
sp->runAction(MoveTo::create(0.3f, Vec2(endPosX, endPosY)));
}
else
{
sp->setPosition(Vec2(endPosX, endPosY));
}
_aryChipSprite.push_back(sp);
}
}
nCount = nCount % aryChipGroup[i];
}
}
// 玩家抢庄字消失;
void NNGameScene::clearRobIcon()
{
for (int i = 0; i<NN_GAME_PLAYER; i++ )
{
m_aryPlayer[i]->setRobIconVisible(false);
}
}
//void NNGameScene::showWinAni(SCORE lGameScore[NN_GAME_PLAYER])
//{
// playGetChipAni();
//
// auto callback = [=]() {
// showWinCup();
// };
//
// runAction(Sequence::create(DelayTime::create(0.3f), CallFunc::create(callback), nullptr));
//}
//// 赢图标显示;
//void NNGameScene::showWinCup()
//{
// cocostudio::ArmatureAnimation* pArmature = _pArmatureEnd->getAnimation();
//
// if (!_bWin)
// {
// if (pArmature != nullptr)
// {
// pArmature->play("lose1", -1, 0);
// _pArmatureEnd->setVisible(true);
// }
//
// playEffect("lose");
// }
// else
// {
// if (pArmature != nullptr)
// {
// pArmature->play("win1", -1, 0);
// _pArmatureEnd->setVisible(true);
// }
//
// playEffect("finalWin");
// }
//
// _ResultPanel->setVisible(true);
//}
void NNGameScene::showPlayerCard()
{
for (int i = 0; i<NN_GAME_PLAYER; i++ )
{
if (_aryActiveStatus[i])
{
uint16 wViewID = SwitchViewChairID(i);
m_aryPlayer[wViewID]->showCard(_aryAllHandCardData[i], NN_MAX_COUNT);
}
}
}
// 收筹码动画;
void NNGameScene::playGetChipAni()
{
vector<Sprite*>::iterator iter = _aryChipSprite.begin();
for (; iter != _aryChipSprite.end(); iter++)
{
Sprite* pSpr = (Sprite*)*iter;
if (pSpr!=nullptr)
{
pSpr->removeFromParent();
}
}
_aryChipSprite.clear();
playEffect("winGold");
for (uint16 wViewID = 0; wViewID< NN_GAME_PLAYER; wViewID++)
{
SCORE nCount = _lViewGameScore[wViewID];
if ( nCount > 0)
{
// 临时筹码精灵数组;
const Vec2& ptHeadPos = m_aryPlayer[wViewID]->getHeadPos();
float endPosX = ptHeadPos.x - _ChipPanel->getPositionX();
float endPosY = ptHeadPos.y - _ChipPanel->getPositionY();
float startPosX = 0;
float startPosY = 0;
SpriteFrameCache* pSpriteFrameCache = SpriteFrameCache::getInstance();
pSpriteFrameCache->addSpriteFramesWithFile("Games/NiuNiu/Table/PinChip.plist");
// 显示筹码数字;
int aryChipGroup[5] = { 5, 4, 3, 2, 1 };
for (int i = 0; i<5; i++)
{
int nNum = nCount / aryChipGroup[i];
if (nNum > 0)
{
std::string chipStr = StringUtils::format("imgChip%d.png", aryChipGroup[i]);
for (int k = 0; k < nNum; k++)
{
auto sp = Sprite::createWithSpriteFrameName(chipStr);
sp->setScale(0.7f);
float spW = sp->getContentSize().width * 0.7f;
float spH = sp->getContentSize().height * 0.7f;
_ChipPanel->addChild(sp);
startPosX = (spW / 2) + (_ChipPanel->getContentSize().width - spW)*cocos2d::rand_0_1();
startPosY = (spH / 2) + (_ChipPanel->getContentSize().height - spH)*cocos2d::rand_0_1();
sp->setPosition(Vec2(startPosX, startPosY));
sp->runAction(Sequence::create(MoveTo::create(0.5f, Vec2(endPosX, endPosY)), RemoveSelf::create(), nullptr));
}
}
nCount = nCount % aryChipGroup[i];
}
}
}
}
void NNGameScene::showCuoPai(uint8 aryCardData[], uint8 cbCardCount)
{
}
void NNGameScene::operateAction(std::string strAction)
{
uint16 wSelfChairID = getSelfChairID();
CC_ASSERT(wSelfChairID<NN_GAME_PLAYER);
if ( _aryActiveStatus[wSelfChairID] )
{
if (strAction == "TiShi")
{
NN_CMD_S_OpenCard stOpenCard = { 0 };
stOpenCard.cbCardType = m_GameLogic.GetCardType(_aryHandCardData, NN_MAX_COUNT, stOpenCard.cbCardData);
if ((NIU_TYPE_1 <= stOpenCard.cbCardType) && (stOpenCard.cbCardType <= NIU_TYPE_10))
{
// 提示;
m_pLocalPlayer->tipCard(stOpenCard);
_btnAutoNiu->setVisible(true);
}
else
{
sendOpenCardMsg();
}
_btnCuoPai->setVisible(false);
}
else if (strAction == "LiangPai")
{
sendOpenCardMsg();
}
else if (strAction == "RobNO")
{
_RobPanel->setVisible(false);
sendRobBankerMsg(false);
}
else if (strAction == "RobYES")
{
_RobPanel->setVisible(false);
sendRobBankerMsg(true);
}
else
{
for (int i = 1; i<=5; i++)
{
if (strAction == StringUtils::format("btnYazhu%d", i))
{
log("我下注啦 %d", i);
_YazhuPanel1->setVisible(false);
sendChipScoreMsg(i);
break;
}
}
}
}
}
void NNGameScene::openGameClock(int iLeftTime, const std::function<void()>& callFunc/* = nullptr*/)
{
closeGameClock();
_imgGameClock->setVisible(true);
TextAtlas* txtClockNum = static_cast<TextAtlas*>(_imgGameClock->getChildByName("txtClockNum"));
txtClockNum->setString(StringUtils::format("%02d", iLeftTime));
txtClockNum->setTag(iLeftTime);
auto callback = [=]() {
int iTime = __max(txtClockNum->getTag(), 0);
if (iTime <= 0) return;
txtClockNum->setString(StringUtils::format("%02d", --iTime));
txtClockNum->setTag(iTime);
if (iTime == 3)
{
_imgGameClock->runAction(RepeatForever::create(JumpBy::create(0.9f, Vec2(0, 0), 20, 3)));
}
if (iTime == 0)
{
//_imgGameClock->stopAllActions();
if (callFunc != nullptr)
{
callFunc();
}
}
};
_imgGameClock->runAction(RepeatForever::create(Sequence::create(DelayTime::create(1.0f), CallFunc::create(callback), nullptr)));
}
void NNGameScene::closeGameClock()
{
_imgGameClock->stopAllActions();
_imgGameClock->setVisible(false);
}
void NNGameScene::showLordUser(bool isplayEffect/* = false*/)
{
if (_wLordUser != INVALID_CHAIR)
{
uint16 wViewID = SwitchViewChairID(_wLordUser);
if (m_aryPlayer[wViewID]->setBankerVisible(true))
{
if (isplayEffect)
{
GamePlayer* pPlayer = getPlayerByChairID(_wLordUser);
std::string strSound = "woman/banker";
if (pPlayer->GetGender() == enMan)
{
strSound = "man/banker";
}
playEffect(strSound);
}
}
}
}
// 发牌结束消息;
void NNGameScene::sendSendCardOverMsg()
{
SendSocketData(NN_SUB_C_SEND_OVER);
}
// 抢庄消息;
void NNGameScene::sendRobBankerMsg(bool bFlag)
{
NN_CMD_C_RobBanker RobBanker;
RobBanker.bRob = bFlag;
SendSocketData(NN_SUB_C_ROB_BANKER, &RobBanker, sizeof(NN_CMD_C_RobBanker));
}
// 加注消息;
void NNGameScene::sendChipScoreMsg(SCORE lChipScore)
{
NN_CMD_C_ChipScore ChipScore;
ChipScore.lScore = lChipScore;
SendSocketData(NN_SUB_C_CHIP_SCORE, &ChipScore, sizeof(NN_CMD_C_ChipScore));
}
// 发送开牌消息;
void NNGameScene::sendOpenCardMsg()
{
SendSocketData(NN_SUB_C_OPEN_CARD);
}
// 设置状态;
void NNGameScene::setOperateStatus(NN_OPERATE_STATUS ops)
{
_spOtherCallBanker->setVisible(ops == NN_OS_CALLBANK);
_spOtherAddScore->setVisible(ops == NN_OS_ADDSCORE0);
_spSelfAddScore->setVisible(ops == NN_OS_ADDSCORE1);
}
// 获取当前玩家数量;
uint8 NNGameScene::getCurPlayerCount()
{
uint8 cbPlayerCount = 0;
for (int i = 0; i < NN_GAME_PLAYER; i++)
{
GamePlayer* pPlayer = m_aryPlayer[i];
if (pPlayer != nullptr && pPlayer->getUserItem(false)!=nullptr )
{
cbPlayerCount++;
}
}
return cbPlayerCount;
}
//玩家金币改变;
void NNGameScene::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());
((NN_GamePlayer*)pPlayer)->updateScore();
}
// 玩家坐标;
Vec2 NNGameScene::GetPlayerPosByUserID(uint32 dwUserID)
{
NN_GamePlayer* pPlayer = (NN_GamePlayer*)getPlayerByUserID(dwUserID);
if (pPlayer == nullptr)
{
return Vec2();
}
//const Vec2 ptHeadPos = pPlayer->getHeadPos();
//Vec2 ptWorldPos = pPlayer->convertToWorldSpace(ptHeadPos);
return pPlayer->getHeadPos();
}
//调用;
GamePlayer* NNGameScene::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);
NN_GamePlayer* pPlayer = m_aryPlayer[wViewID];
pPlayer->setUserItem(pIClientUserItem);
return pPlayer;
}
return NULL;
}
//椅子号视图转换;
WORD NNGameScene::SwitchViewChairID(WORD wChairID)
{
//参数判断;
if (wChairID == INVALID_CHAIR) return INVALID_CHAIR;
WORD wSelfChairID = getSelfChairID();
if (wSelfChairID == INVALID_CHAIR) return INVALID_CHAIR;
//转换椅子;
WORD wChairCount = NN_GAME_PLAYER;
WORD wViewChairID = (wChairID + wChairCount - wSelfChairID + NN_VIEW_SELF_ID) % wChairCount;
return wViewChairID;
}
//本人进入游戏 GameFrameBase.cpp调用;
void NNGameScene::upSelfPlayerInfo()
{
log("Self Enter!!");
return;
}
/************************************* 语音 ***********************************************************/
// 按住语音按钮;
void NNGameScene::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/NiuNiu/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();
}
}
//获到性别字符串;
std::string NNGameScene::getUserGender(int cbGender)
{
if (cbGender == 0)
{
return "Boy";
}
return "Girl";
}
//播放发牌声音;
void NNGameScene::playSendCardEffect()
{
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
pAudio->playEffect("Games/NiuNiu/Audio/effDealCard.mp3");
}
//播放快捷语音;
void NNGameScene::playFastVoice(int cbGender, int voiceIndex)
{
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
std::string strGender = getUserGender(cbGender);
std::string strAudioRes = StringUtils::format("Games/NiuNiu/Audio/FastVoice/%s/%d.mp3", strGender.c_str(), voiceIndex);
log("the strAudioRes is== %s", strAudioRes.c_str());
pAudio->playEffect(strAudioRes.c_str());
}
//播放牛音效;
void NNGameScene::playCowValue(int cbGender, int cowIndex)
{
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
std::string strGender = getUserGender(cbGender);
std::string strAudioRes = StringUtils::format("Games/NiuNiu/Audio/CowValue/%s/cow%d.mp3", strGender.c_str(), cowIndex);
log("the strAudioRes is== %s", strAudioRes.c_str());
pAudio->playEffect(strAudioRes.c_str());
}
//播放音效;
void NNGameScene::playEffect(std::string strPath)
{
CocosDenshion::SimpleAudioEngine* pAudio = CocosDenshion::SimpleAudioEngine::getInstance();
std::string strAudioRes = StringUtils::format("Games/NiuNiu/Audio/%s.mp3", strPath.c_str());
pAudio->playEffect(strAudioRes.c_str());
}
//播放点击音效;
void NNGameScene::playBtnClickEffect()
{
YSAudioEngine::Instance().playBtnClickEffect();
}
/************************************* 房间信息 ***********************************************************/
// 房间信息消息;
void NNGameScene::OnSocketSubPrivateRoomInfo(CMD_GF_Private_Room_Info* pNetInfo)
{
m_PrivateRoomInfo = *pNetInfo;
m_dwRoomID = pNetInfo->dwRoomNum;
string strRoomID = StringUtils::format("房号:%d", m_dwRoomID);
_txtRoomID->setString(utility::a_u8(strRoomID));
_txtRoomID->setVisible(true);
_OpenResultScene->SetRoomID(utility::a_u8(strRoomID));
uint32 dwPlayCout = __max(pNetInfo->dwPlayCout+1, 1);
dwPlayCout = __min(dwPlayCout, pNetInfo->dwPlayTotal);
m_dwPlayCout = dwPlayCout;
string strPlayCount = StringUtils::format("%u/%u", dwPlayCout, pNetInfo->dwPlayTotal);
cocos2d::log("dwPlayCout = %d", pNetInfo->dwPlayCout);
_txtJushu->setString(utility::a_u8(strPlayCount.c_str()));
_txtJushu->setVisible(true);
// 规则;
if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_BANKER_OWNER) == eNNRuleEnum_BANKER_OWNER)
{
_txtRoomRule->setString(utility::a_u8("霸王庄"));
}
else if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_BAYONET) == eNNRuleEnum_BAYONET)
{
_txtRoomRule->setString(utility::a_u8("拼刺刀"));
}
else
{
_txtRoomRule->setString(utility::a_u8("抢庄玩法"));
}
ShowGameRule(pNetInfo);
NN_GamePlayer* pPlayer = (NN_GamePlayer*)getPlayerByUserID(pNetInfo->dwCreateUserID);
if (pPlayer != nullptr) pPlayer->setOwner(true);
if (pNetInfo->bStartGame)
{
//如果游戏已开始则隐藏“返回大厅”按钮,显示“解散房间”按钮;
_btnWXInvite->setVisible(false);
_btnStartGame->setVisible(false);
_btnWXDismiss->setVisible(true);
_btnLeave->setVisible(false);
//私人场已经开始,重连上游戏自带发送准备消息;
GamePlayer* pSelfPlayer = getSelfGamePlayer();
if (!_ResultPanel->isVisible() && (pSelfPlayer != nullptr) && (pSelfPlayer->GetUserStatus() == US_SIT) && (m_cbGameStatus == NN_GS_TK_FREE))
{
//m_kGameMission.SendSocketData(MDM_GF_FRAME, SUB_GF_USER_READY, 0, 0);
SendUserReady();
}
}
else
{
GamePlayer* pPlayer = getSelfGamePlayer();
//如果房间主人是自已则隐藏“返回大厅”按钮,显示“解散房间”按钮;
if (pPlayer != nullptr && pNetInfo->dwCreateUserID == pPlayer->GetUserID())
{
_btnLeave->setVisible(false);
_btnWXDismiss->setVisible(true);
}
//游戏未开始显示微信分享按钮
if (pNetInfo->dwPlayCout <= 0)
{
_btnWXInvite->setVisible(true);
_btnStartGame->setVisible(true);
}
}
}
// 游戏规则
void NNGameScene::ShowGameRule(CMD_GF_Private_Room_Info* pNetInfo)
{
if (pNetInfo == nullptr) return;
std::string strPlayCount = StringUtils::format(" %d局, ", pNetInfo->dwPlayTotal);
std::string strGameRuleIdex = "抢庄玩法";
m_strGameTitle = "牛牛~抢庄";
// 规则;
if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_BANKER_OWNER) == eNNRuleEnum_BANKER_OWNER)
{
strGameRuleIdex = "霸王庄玩法";
m_strGameTitle = "牛牛~霸王庄";
}
else if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_BAYONET) == eNNRuleEnum_BAYONET)
{
strGameRuleIdex = "拼刺刀玩法";
m_strGameTitle = "牛牛~拼刺刀";
}
if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_WHN) == eNNRuleEnum_WHN)
{
strGameRuleIdex += ", 五花牛";
}
if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_BOMB) == eNNRuleEnum_BOMB)
{
strGameRuleIdex += ", 炸弹";
}
if ((pNetInfo->bGameRuleIdex&eNNRuleEnum_WXN) == eNNRuleEnum_WXN)
{
strGameRuleIdex += ", 五小牛";
}
m_strGameRuleInfo = strPlayCount + strGameRuleIdex + ",";
}
// 私人场结束;
void NNGameScene::OnSocketSubPrivateEnd(void* data, int dataSize)
{
m_bPrivateEnd = true;
// 申请解散界面;
DismissScene::Instance().hide();
GamePlayer* players[NN_GAME_PLAYER];
for (int i = 0; i < NN_GAME_PLAYER; i++)
{
players[i] = getPlayerByChairID(i);
}
if (_OpenResultScene)
{
DataStream kDataStream(data, dataSize);
NN_CMD_S_Private_End_Info kNetInfo;
kNetInfo.StreamValue(kDataStream, false);
//SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
//_OpenResultScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);
// 欢乐场
if (m_PrivateRoomInfo.cbUnionGoldOpen == 1)
{
/*SCORE lGameGold = m_PrivateRoomInfo.lGameGold*m_PrivateRoomInfo.dwPlayCost;
_OpenResultScene->ShowGameResult(&kNetInfo, players, (m_PrivateRoomInfo.cbUnionGoldOpen == 1), lGameGold, m_PrivateRoomInfo.lScoreMultiple);*/
_OpenResultScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo, m_PrivateScoreInfo);
}
else
{
_OpenResultScene->ShowGameResult(&kNetInfo, players, m_PrivateRoomInfo.cbBaseScore);
}
}
if (_ResultPanel->isVisible())
{
_btnLookon->setVisible(true);
_btnContinue->setVisible(false);
}
else
{
_OpenResultScene->setVisible(true);
}
// 游戏结束停止网络;
PrivateRoomEnd();
}
void NNGameScene::onEventShowPrivate(cocos2d::EventCustom *event)
{
//if (m_pPrivateScene)
//{
// m_pPrivateScene->pushScene();
//}
}
// 请求解散房间;
void NNGameScene::OnSocketSubPrivateDismissInfo(CMD_GF_Private_Dismiss_Info* pNetInfo)
{
std::string aryName[NN_GAME_PLAYER];
BYTE aryResult[NN_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 < NN_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 < NN_GAME_PLAYER)
{
aryResult[dwChairID] = 2;
}
if (dwMyChairID == dwChairID)
{
bHasSelf = true;
}
}
GamePlayer* players[NN_GAME_PLAYER];
for (int i = 0; i < NN_GAME_PLAYER; i++)
{
players[i] = getPlayerByChairID(i);
}
DismissScene::Instance().show(aryResult, players, !bHasSelf, NN_GAME_PLAYER);
}
void NNGameScene::OnSocketSubPrivateDismissResult(CMD_GF_Private_Dismiss_Result* pNetInfo)
{
if (pNetInfo->bSuccess && false == m_PrivateRoomInfo.bStartGame)
{
EventLeaveGame(nullptr);
}
else
{
DismissScene::Instance().hide();
}
}
void NNGameScene::ShowGoldMoveToArea(SCORE lScore, uint8 wStartViewID, uint8 wTargetViewID)
{
float fDelayTime = 0.1f;
//CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sound_res/coins_fly_in.wav");
Vec2 ptStart = m_aryPlayer[wStartViewID]->getHeadPos();
Vec2 ptEnd = m_aryPlayer[wTargetViewID]->getHeadPos();
cocos2d::Size viewsize = Director::getInstance()->getVisibleSize();
for (int index = 0; index < lScore; ++index) {
// 创建筹码;
auto pgold = Sprite::create("Games/NiuNiu/Table/im_gold.png");
pgold->setPosition(ptStart);
pgold->setOpacity(0);
pgold->runAction(FadeTo::create(0.1f, 255));
auto xmove = std::rand() % 50;
auto ymove = std::rand() % 50;
if ((xmove%2)>0)
{
xmove = 0 - xmove;
}
if ((ymove % 2) > 0)
{
ymove = 0 - ymove;
}
auto target = Vec2(ptEnd.x + xmove, ptEnd.y - ymove);
FiniteTimeAction * paction = EaseOut::create(MoveTo::create(0.42f, target), 1);
// 不是第一个筹码;
if (index > 0)
{
paction = Sequence::create(DelayTime::create(rand_0_1() / 5.f), paction, FadeOut::create(0.1f), RemoveSelf::create(), nullptr);
}
else
{
paction = Sequence::create(paction, FadeOut::create(0.1f), RemoveSelf::create(), nullptr);
}
pgold->runAction(paction);
_GamePanel->addChild(pgold);
// 筹码缓存;
//_aryChipSprite.push_back(pgold);
fDelayTime += (0.42f + 0.1f);
}
fDelayTime += (0.42f + 0.8f);
playEffect("flygold");
}
std::string NNGameScene::getGameRule(uint32 dwGameRule)
{
std::string strGameRuleIdex = "抢庄玩法";
// 规则;
if ((dwGameRule&eNNRuleEnum_BANKER_OWNER) == eNNRuleEnum_BANKER_OWNER)
{
strGameRuleIdex = "霸王庄玩法";
}
else if ((dwGameRule&eNNRuleEnum_BAYONET) == eNNRuleEnum_BAYONET)
{
strGameRuleIdex = "拼刺刀玩法";
}
if ((dwGameRule&eNNRuleEnum_WHN) == eNNRuleEnum_WHN)
{
strGameRuleIdex += ", 五花牛";
}
if ((dwGameRule&eNNRuleEnum_BOMB) == eNNRuleEnum_BOMB)
{
strGameRuleIdex += ", 炸弹";
}
if ((dwGameRule&eNNRuleEnum_WXN) == eNNRuleEnum_WXN)
{
strGameRuleIdex += ", 五小牛";
}
return strGameRuleIdex;
}