_getZid(); $teamUuid = $nodeId . '_' . $zid . '_' . md5($this->_getAccountId() . $this->_getNowTime()); /*if (!in_array(array ( self::MATCH_MODE_NORMAL, self::MATCH_MODE_RANK, self::MATCH_MODE_PVE, ), $matchMode)) { $this->_rspErr(1, 'match mode error'); return; }*/ $userDb = $this->_getOrmUserInfo(); error_log("CREATE TEAM : " . $userDb['account_id']); //验证pve_instance_id合法性 if ($pveInstanceId){ // if ($userDb['level'] < \mt\LevelUp::USER_LEVEL_PVE_MATCH_LIMIT){ if ($userDb['star_num'] < \mt\StarLevel::STAR_NUM_PVE_MATCH_LIMIT){ $this->_rspErr(1,'Not agreed terms'); return; } $pveGame = \mt\PveGemini::get($pveInstanceId); if (!$pveGame){ $this->_rspErr(1, 'pve_instance_id error'); return; } if (!in_array($pveInstanceId,\mt\PveGemini::getAbleCombatMeta($userDb['pve_instance_id']))){ $this->_rspErr(1, "You can't challenge beyond your level"); return; } } if ($matchMode == self::MATCH_MODE_RANK){ // if ($userDb['level'] < \mt\LevelUp::USER_LEVEL_RANK_MATCH_LIMIT){ if ($userDb['star_num'] < \mt\StarLevel::STAR_NUM_RANK_MATCH_LIMIT){ $this->_rspErr(1,'Not agreed terms'); return; } } $userDto = User::toPreset($userDb); $userDto['is_leader'] = 1; $userDto['is_ready'] = 1; $userDto['createtime'] = $userDb['createtime']; $teamDb = array( 'team_uuid' => $teamUuid, 'state' => 0, 'payload' => '', 'match_mode' => $matchMode, 'pve_instance_id' => $pveInstanceId, 'slot_num' => 1, 'member_list' => array($userDto)); $r = $this->_getRedis($teamUuid); $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspData(array( 'team_uuid' => $teamUuid )); } public function teamInfo() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $r->pexpire(TEAMID_KEY . $teamUuid, 1000*600); $this->_rspData(array( 'team_info' => $teamDb )); } public function updateTeam(){ $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $userDb = $this->_getOrmUserInfo(); $userDto = User::toPreset($userDb); foreach ($teamDb['member_list'] as $key=>$member) { if ($member['account_id'] == $this->_getAccountId()) { $userDto['is_leader'] = $member['is_leader']; $userDto['is_ready'] = $member['is_ready']; $userDto['createtime'] = $member['createtime']; $teamDb['member_list'][$key] = $userDto; } } $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspData(array( 'team_uuid' => $teamUuid )); } public function joinTeam() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $userDb = $this->_getOrmUserInfo(); if ($teamDb['match_mode'] == self::MATCH_MODE_RANK && // $userDb['level'] < \mt\LevelUp::USER_LEVEL_RANK_MATCH_LIMIT){ $userDb['star_num'] < \mt\StarLevel::STAR_NUM_RANK_MATCH_LIMIT){ $this->_rspErr(1,'Not agreed terms'); return; } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId()) { $this->_rspData(array( 'team_uuid' => $teamUuid )); return; } } $userDb = User::find($this->_getAccountId()); //验证pve_instance_id合法性 if ($teamDb['pve_instance_id']>0){ if (!in_array($teamDb['pve_instance_id'],\mt\PveGemini::getAbleCombatMeta($userDb['pve_instance_id']))) { $this->_rspErr(1, 'No challenge'); return; } // if ($userDb['level'] < \mt\LevelUp::USER_LEVEL_PVE_MATCH_LIMIT){ if ($userDb['star_num'] < \mt\StarLevel::STAR_NUM_PVE_MATCH_LIMIT){ $this->_rspErr(1,'Not agreed terms'); return; } } $userDto = User::toPreset($userDb); $userDto['createtime'] = $userDb['createtime']; array_push($teamDb['member_list'], $userDto); $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspData(array( 'team_uuid' => $teamUuid )); } public function leaveTeam() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $newMemberList = array(); $isLeader = false; foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] == 1){ $isLeader = true; } if ($member['account_id'] != $this->_getAccountId()) { array_push($newMemberList, $member); } } if (count($newMemberList)<1){ $this->delTeamDb($r, $teamUuid); $this->_rspOk(); return; } if ($isLeader){ $newMemberList[0]['is_leader'] = 1; } $teamDb['member_list'] = $newMemberList; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function kickout() { $teamUuid = getReqVal('team_uuid', ''); $account_id = getReqVal('target_id', ''); if (! $account_id){ $this->_rspErr(1, 'target_id param error'); return; } $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $temp = array_map(function ($val){ return $val['account_id']; },$teamDb['member_list']); if(! in_array($account_id,$temp)){ $this->_rspErr(1, 'The team do not have users'); return; } // if(! in_array($account_id,array_column($teamDb['member_list'],'account_id'))){ // $this->_rspErr(1, 'The team do not have users'); // return; // } if ($account_id == $this->_getAccountId()){ $this->_rspErr(1, 'do not get myself out of line'); return; } $newMemberList = array(); foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } if ($member['account_id'] != $account_id) { array_push($newMemberList, $member); } } $teamDb['member_list'] = $newMemberList; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function closeSlot() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } } if ($teamDb['slot_num'] <= 1){ $this->_rspErr(1, 'Minimum size of team'); return; } if (count($teamDb['member_list'])== 4){ $this->_rspErr(1, "Can't shut down"); return; } $teamDb['slot_num']-=1; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function openSlot() { $teamUuid = getReqVal('team_uuid', ''); $slotNum = getReqVal('slot_num', 1); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspOk(); return; } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } } if (count($teamDb['member_list'])>$slotNum){ $this->_rspErr(1, 'slot_num Insufficient '); return; } $teamDb['slot_num'] = $slotNum; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function handover() { $teamUuid = getReqVal('team_uuid', ''); $account_id = getReqVal('target_id', ''); if (! $account_id){ $this->_rspErr(1, 'target_id param error'); return; } $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $temp = array_map(function ($val){ return $val['account_id']; },$teamDb['member_list']); if(! in_array($account_id,$temp)){ $this->_rspErr(1, 'The team do not have users'); return; } // if(! in_array($account_id,array_column($teamDb['member_list'],'account_id'))){ // $this->_rspErr(1, 'The team do not have users'); // return; // } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } } if ($account_id == $this->_getAccountId()){ $this->_rspErr(1, " You're already the captain "); return; } foreach ($teamDb['member_list'] as &$member) { if ($member['account_id'] == $this->_getAccountId()){ $member['is_leader'] = 0; } if ($member['account_id'] == $account_id){ $member['is_leader'] = 1; } } $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function cancel() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } } $teamDb['state'] = 0; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function startGame() { $teamUuid = getReqVal('team_uuid', ''); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } foreach ($teamDb['member_list'] as $member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ $this->_rspErr(1, 'You are not the captain.'); return; } } $teamDb['state'] = 1; $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function doReady(){ $teamUuid = getReqVal('team_uuid', ''); $readyState = getReqVal('ready_state', 0); //1:准备 0:取消 if(!in_array($readyState,array(0,1))){ $this->_rspErr(1, 'ready_state param error'); return; } $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } foreach ($teamDb['member_list'] as &$member) { if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] == 1){ $this->_rspErr(1, 'Captain no operation'); return; } if ($member['account_id'] == $this->_getAccountId()){ $member['is_ready'] = $readyState?:0; } } $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } public function setHero(){ $teamUuid = getReqVal('team_uuid', ''); $heroUid = getReqVal('hero_uid', ''); $heroDb = Hero::find($heroUid); if (! $heroDb){ $this->_rspErr(1, 'hero_uid param error'); return; } $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $this->_updateUserInfo(array( 'hero_id' => $heroUid )); $newUserInfo = User::toPreset($this->_getOrmUserInfo()); foreach ($teamDb['member_list'] as &$member) { if ($member['account_id'] == $this->_getAccountId()){ $newUserInfo['is_leader'] = $member['is_leader']; $newUserInfo['is_ready'] = $member['is_ready']; $member = $newUserInfo; } } $this->saveTeamDb($r, $teamUuid, $teamDb); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $propertyChgService->toDto() )); } public function setPreset(){ $teamUuid = getReqVal('team_uuid', ''); $heroId = getReqVal('hero_uid',0); $chipPageId = getReqVal('chip_page',0); $weaponUid1 = getReqVal('weapon_uid1',0); $weaponUid2 = getReqVal('weapon_uid2',0); $skillId = getReqVal('skill_id',0); $r = $this->_getRedis($teamUuid); $teamDb = $this->readTeamDb($r, $teamUuid); if (empty($teamDb)) { $this->_rspErr(1, 'The team has been disbanded'); return; } $heroDb = Hero::find($heroId); if (! $heroDb){ $this->_rspErr(1, "You don't have the hero yet"); return; } $chipPageDb = ChipPage::find($chipPageId); if (! $chipPageDb){ $this->_rspErr(1, "You don't have the chip page"); return; } if ($weaponUid1){ $gunDb1 = Gun::find($weaponUid1); if (!$gunDb1){ $this->_rspErr(1, "You don't have the gun1 yet"); return; } } if ($weaponUid2){ $gunDb2 = Gun::find($weaponUid2); if (!$gunDb2){ $this->_rspErr(1, "You don't have the gun2 yet"); return; } } $skillMeta = mt\Skill::get($skillId); if (! $skillMeta){ $this->_rspErr(1,'skill_id parameter error'); return ; } HeroPreset::upsertPreset($heroId,$skillId,$chipPageId,$weaponUid1,$weaponUid2); $newUserInfo = User::toPreset($this->_getOrmUserInfo()); foreach ($teamDb['member_list'] as &$member) { if ($member['account_id'] == $this->_getAccountId()){ $newUserInfo['is_leader'] = $member['is_leader']; $newUserInfo['is_ready'] = $member['is_ready']; $member = $newUserInfo; } } $this->saveTeamDb($r, $teamUuid, $teamDb); $this->_rspOk(); } // public function setHeroSkin(){ // $teamUuid = getReqVal('team_uuid', ''); // $heroUniId = getReqVal('hero_uid', 0); // $skinId = getReqVal('skin_id', 0); // $r = $this->_getRedis($teamUuid); // $teamDb = $this->readTeamDb($r, $teamUuid); // if (empty($teamDb)) { // $this->_rspErr(1, 'The team has been disbanded'); // return; // } // $heroDb = Hero::find($heroUniId); // $heroSkinDb = HeroSkin::find($skinId); // if (!$heroDb) { // $this->_rspErr(1, "You don't have the hero yet"); // return; // } // if (!$heroSkinDb) { // $this->_rspErr(2, "You don't have the skin yet"); // return; // } // HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); // $newUserInfo = User::toPreset($this->_getOrmUserInfo()); // foreach ($teamDb['member_list'] as &$member) { // if ($member['account_id'] == $this->_getAccountId()){ // $newUserInfo['is_leader'] = $member['is_leader']; // $newUserInfo['is_ready'] = $member['is_ready']; // $member = $newUserInfo; // } // // } // $this->saveTeamDb($r, $teamUuid, $teamDb); // $this->_rspOk(); // } public function getPveFragmentNumOrDay(){ $todayPveGetHeroFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_HERO_FRAGMENT_NUM, 0); $todayPveGetGunFragmentNum = myself()->_getDailyV(TN_DAILY_PVE_GET_GUN_FRAGMENT_NUM, 0); $this->_rspData(array( 'heroNum'=>$todayPveGetHeroFragmentNum, 'gunNum'=>$todayPveGetGunFragmentNum, )); } private function readTeamDb($r, $teamUuid) { $teamDbStr = $r->get(TEAMID_KEY . $teamUuid); if (empty($teamDbStr)) { return null; } $teamDb = json_decode($teamDbStr, true); return $teamDb; } private function saveTeamDb($r, $teamUuid, $teamDb) { $r->set(TEAMID_KEY . $teamUuid, json_encode($teamDb)); $r->pexpire(TEAMID_KEY . $teamUuid, 1000*600); } private function delTeamDb($r, $teamUuid){ $r->del(TEAMID_KEY . $teamUuid); } }