// 定时器功能相关接口 // 定时器激活,记录定时器信息,返回客户端结果消息 double CScript::SetTimer(const char* cmd, char* retStr) { CPlayer* player = dynamic_cast<CPlayer*>(p_SrcShape); if(!player) return 0; if(player->GetCountTimerNum()>=CCountTimerList::GetMaxTimerNum()) return 0; int countType = GetIntParam(cmd, 0); // 计时类型 if(countType==ERROR_CODE) return 0; int timeNum = GetIntParam(cmd, 1); // 计时时长 if(timeNum==ERROR_CODE) return 0; int timerType = GetIntParam(cmd, 2); // 定时器类型 if(timerType==ERROR_CODE) return 0; const tagCountTimerParam& param = CCountTimerList::GetCountTimerParam(timerType); if(param.m_dwType==-1) return 0; CPlayer::tagCountTimer timer; player->SetCurCountTimerID(player->GetCurCountTimerID()+1); timer.m_dwID = player->GetCurCountTimerID();// 定时器ID timer.m_bCountType = (0 != countType);//计时类型,0:顺序 1:倒序 time_t curTime; time(&curTime); timer.m_dwCountTime = curTime;// 计时开始点, 单位毫秒 timer.m_dwRetTime = timeNum; // 计时剩余值,单位毫秒 timer.m_dwStartRetTime = timer.m_dwRetTime; timer.m_dwTimerType = timerType; player->AddCountTimer(timer); // 发送消息给客户端 CMessage msg(MSG_S2C_OTHER_SETTIMER); vector<BYTE> pBA; _AddToByteArray(&pBA, (char)timer.m_bCountType); _AddToByteArray(&pBA, (DWORD)timer.m_dwID); _AddToByteArray(&pBA, (DWORD)timer.m_dwRetTime); _AddToByteArray(&pBA, (DWORD)timer.m_dwStartRetTime); _AddToByteArray(&pBA, param.m_strPicPath.c_str()); _AddToByteArray(&pBA, param.m_strBackPicPath.c_str()); _AddToByteArray(&pBA, param.m_strTextPath.c_str()); _AddToByteArray(&pBA, param.m_strText.c_str()); _AddToByteArray(&pBA, param.m_strTimeoutText.c_str()); _AddToByteArray(&pBA, (DWORD)param.m_dwTextTime); _AddToByteArray(&pBA, (DWORD)param.m_dwTextViewTime); msg.Add((long)pBA.size()); if(pBA.size()) msg.AddEx(&pBA[0], (long)pBA.size()); msg.SendToPlayer(player->GetExID()); return timer.m_dwID; }
// 取得玩家定时器状态 double CScript::GetPlayerTimer(const char* cmd, char* retStr) { CPlayer* player = dynamic_cast<CPlayer*>(p_SrcShape); if(!player) return 0; return player->GetCountTimerNum(); }