|
想要查看内容赶紧注册登陆吧!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
#include "Stdafx.h"
#include "AndroidUserItemSink.h"
//////////////////////////////////////////////////////////////////////////
//辅助时间
#define TIME_LESS 1 //最少时间
//游戏时间
#define TIME_USER_CALL_BANKER 2 //叫庄定时器
#define TIME_USER_START_GAME 3 //开始定时器
#define TIME_USER_ADD_SCORE 3 //下注定时器
#define TIME_USER_OPEN_CARD 12 //摊牌定时器
//游戏时间
#define IDI_ANDROID_ITEM_SINK 100
#define IDI_START_GAME (IDI_ANDROID_ITEM_SINK+0) //开始时间
#define IDI_CALL_BANKER (IDI_ANDROID_ITEM_SINK+1) //叫庄时间
#define IDI_USER_ADD_SCORE (IDI_ANDROID_ITEM_SINK+2) //下注时间
#define IDI_OPEN_CARD (IDI_ANDROID_ITEM_SINK+3) //开牌时间
//////////////////////////////////////////////////////////////////////////
//构造函数
CAndroidUserItemSink::CAndroidUserItemSink()
{
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
//接口变量
m_pIAndroidUserItem=NULL;
return;
}
//析构函数
CAndroidUserItemSink::~CAndroidUserItemSink()
{
}
//接口查询
void * CAndroidUserItemSink:ueryInterface(REFGUID Guid, DWORD dwQueryVer)
{
QUERYINTERFACE(IAndroidUserItemSink,Guid,dwQueryVer);
QUERYINTERFACE_IUNKNOWNEX(IAndroidUserItemSink,Guid,dwQueryVer);
return NULL;
}
//初始接口
bool CAndroidUserItemSink::Initialization(IUnknownEx * pIUnknownEx)
{
//查询接口
ASSERT(QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem)!=NULL);
m_pIAndroidUserItem=QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx,IAndroidUserItem);
//错误判断
if (m_pIAndroidUserItem==NULL)
{
ASSERT(FALSE);
return false;
}
return true;
}
//重置接口
bool CAndroidUserItemSink::RepositionSink()
{
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
return true;
}
//时间消息
bool CAndroidUserItemSink::OnEventTimer(UINT nTimerID)
{
switch (nTimerID)
{
case IDI_START_GAME: //开始定时器
{
//发送准备
m_pIAndroidUserItem->SendUserReady(NULL,0);
return true;
}
case IDI_CALL_BANKER: //叫庄定时
{
//设置变量
CMD_C_CallBanker CallBanker;
CallBanker.bBanker = rand()%2;
//发送信息
m_pIAndroidUserItem->SendSocketData(SUB_C_CALL_BANKER,&CallBanker,sizeof(CallBanker));
return true;
}
case IDI_USER_ADD_SCORE: //加注定时
{
//可下注筹码
LONGLONG lUserMaxScore[GAME_PLAYER];
ZeroMemory(lUserMaxScore,sizeof(lUserMaxScore));
LONGLONG lTemp=m_lTurnMaxScore;
for (WORD i=0;i<GAME_PLAYER;i++)
{
if(i>0)lTemp/=2;
lUserMaxScore=__max(lTemp,1L);
}
//发送消息
CMD_C_AddScore AddScore;
AddScore.lScore=lUserMaxScore[rand()%4];
m_pIAndroidUserItem->SendSocketData(SUB_C_ADD_SCORE,&AddScore,sizeof(AddScore));
return true;
}
case IDI_OPEN_CARD: //开牌定时
{
//发送消息
CMD_C_OxCard OxCard;
OxCard.bOX=(m_GameLogic.GetCardType(m_HandCardData,MAX_COUNT)>0)?TRUE:FALSE;
m_pIAndroidUserItem->SendSocketData(SUB_C_OPEN_CARD,&OxCard,sizeof(OxCard));
return true;
}
}
return false;
}
//游戏消息
bool CAndroidUserItemSink::OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
switch (wSubCmdID)
{
case SUB_S_CALL_BANKER: //用户叫庄
{
//消息处理
return OnSubCallBanker(pData,wDataSize);
}
case SUB_S_GAME_START: //游戏开始
{
//消息处理
return OnSubGameStart(pData,wDataSize);
}
case SUB_S_ADD_SCORE: //用户下注
{
//消息处理
return OnSubAddScore(pData,wDataSize);
}
case SUB_S_SEND_CARD: //发牌消息
{
//消息处理
return OnSubSendCard(pData,wDataSize);
}
case SUB_S_OPEN_CARD: //用户摊牌
{
//消息处理
return OnSubOpenCard(pData,wDataSize);
}
case SUB_S_PLAYER_EXIT: //用户强退
{
//消息处理
return OnSubPlayerExit(pData,wDataSize);
}
case SUB_S_GAME_END: //游戏结束
{
//消息处理
return OnSubGameEnd(pData,wDataSize);
}
}
//错误断言
ASSERT(FALSE);
return true;
}
//游戏消息
bool CAndroidUserItemSink::OnEventFrameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)
{
return true;
}
//场景消息
bool CAndroidUserItemSink::OnEventSceneMessage(BYTE cbGameStatus, bool bLookonOther, VOID * pData, WORD wDataSize)
{
switch (cbGameStatus)
{
case GS_TK_FREE: //空闲状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusFree)) return false;
//开始时间
UINT nElapse=rand()%(3)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
return true;
}
case GS_TK_CALL: // 叫庄状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusCall)) return false;
CMD_S_StatusCall * pStatusCall=(CMD_S_StatusCall *)pData;
//始叫用户
if(pStatusCall->wCallBanker==m_pIAndroidUserItem->GetChairID())
{
//叫庄时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_BANKER,nElapse);
}
return true;
}
case GS_TK_SCORE: //下注状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusScore)) return false;
CMD_S_StatusScore * pStatusScore=(CMD_S_StatusScore *)pData;
//设置变量
m_lTurnMaxScore=pStatusScore->lTurnMaxScore;
WORD wMeChairId = m_pIAndroidUserItem->GetChairID();
//设置筹码
if (pStatusScore->lTurnMaxScore>0L && pStatusScore->lTableScore[wMeChairId]==0L)
{
//下注时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_USER_ADD_SCORE,nElapse);
}
return true;
}
case GS_TK_PLAYING: //游戏状态
{
//效验数据
if (wDataSize!=sizeof(CMD_S_StatusPlay)) return false;
CMD_S_StatusPlay * pStatusPlay=(CMD_S_StatusPlay *)pData;
//设置变量
m_lTurnMaxScore=pStatusPlay->lTurnMaxScore;
WORD wMeChiarID=m_pIAndroidUserItem->GetChairID();
CopyMemory(m_HandCardData,pStatusPlay->cbHandCardData[wMeChiarID],MAX_COUNT);
//控件处理
if(pStatusPlay->bOxCard[wMeChiarID]==0xff)
{
//开牌时间
UINT nElapse=rand()%(6)+TIME_LESS*2;
m_pIAndroidUserItem->SetGameTimer(IDI_OPEN_CARD,nElapse);
}
return true;
}
}
ASSERT(FALSE);
return false;
}
//用户进入
void CAndroidUserItemSink::OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户离开
void CAndroidUserItemSink::OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户积分
void CAndroidUserItemSink::OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户状态
void CAndroidUserItemSink::OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户段位
void CAndroidUserItemSink::OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)
{
return;
}
//用户叫庄
bool CAndroidUserItemSink::OnSubCallBanker(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_CallBanker)) return false;
CMD_S_CallBanker * pCallBanker=(CMD_S_CallBanker *)pBuffer;
//始叫用户
if(pCallBanker->wCallBanker==m_pIAndroidUserItem->GetChairID())
{
//叫庄时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_CALL_BANKER,nElapse);
}
return true;
}
//游戏开始
bool CAndroidUserItemSink::OnSubGameStart(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_GameStart)) return false;
CMD_S_GameStart * pGameStart=(CMD_S_GameStart *)pBuffer;
//设置变量
m_lTurnMaxScore=pGameStart->lTurnMaxScore;
//设置筹码
if (pGameStart->lTurnMaxScore>0)
{
//下注时间
UINT nElapse=rand()%(4)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_USER_ADD_SCORE,nElapse);
}
return true;
}
//用户下注
bool CAndroidUserItemSink::OnSubAddScore(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_AddScore)) return false;
CMD_S_AddScore * pAddScore=(CMD_S_AddScore *)pBuffer;
return true;
}
//发牌消息
bool CAndroidUserItemSink::OnSubSendCard(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_SendCard)) return false;
CMD_S_SendCard * pSendCard=(CMD_S_SendCard *)pBuffer;
//设置数据
WORD wMeChiarID=m_pIAndroidUserItem->GetChairID();
CopyMemory(m_HandCardData,pSendCard->cbCardData[wMeChiarID],sizeof(m_HandCardData));
//开牌时间
UINT nElapse=rand()%(6)+TIME_LESS*2;
m_pIAndroidUserItem->SetGameTimer(IDI_OPEN_CARD,nElapse);
return true;
}
//用户摊牌
bool CAndroidUserItemSink::OnSubOpenCard(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_Open_Card)) return false;
CMD_S_Open_Card * pOpenCard=(CMD_S_Open_Card *)pBuffer;
return true;
}
//用户强退
bool CAndroidUserItemSink::OnSubPlayerExit(const void * pBuffer, WORD wDataSize)
{
//效验数据
if (wDataSize!=sizeof(CMD_S_PlayerExit)) return false;
CMD_S_PlayerExit * pPlayerExit=(CMD_S_PlayerExit *)pBuffer;
return true;
}
//游戏结束
bool CAndroidUserItemSink::OnSubGameEnd(const void * pBuffer, WORD wDataSize)
{
//效验参数
if (wDataSize!=sizeof(CMD_S_GameEnd)) return false;
CMD_S_GameEnd * pGameEnd=(CMD_S_GameEnd *)pBuffer;
//删除定时器
m_pIAndroidUserItem->KillGameTimer(IDI_CALL_BANKER);
m_pIAndroidUserItem->KillGameTimer(IDI_USER_ADD_SCORE);
m_pIAndroidUserItem->KillGameTimer(IDI_OPEN_CARD);
//开始时间
UINT nElapse=rand()%(3)+TIME_LESS;
m_pIAndroidUserItem->SetGameTimer(IDI_START_GAME,nElapse);
//清理变量
m_lTurnMaxScore = 0;
ZeroMemory(m_HandCardData,sizeof(m_HandCardData));
return true;
}
//组件创建函数
DECLARE_CREATE_MODULE(AndroidUserItemSink);
//////////////////////////////////////////////////////////////////////////
|
|