_getGameId().'_'.$channel.'_'.$openId; // $userDb = User::find($accountId); // if (!$userDb){ // $this->_rspErr(1, 'user not found'); // return; // } $info = array( 'loginVal' => 0, 'battleTimes' => 0, 'winTimes' => 0, 'kills' => 0, 'getGoldVal' => 0, ); $accountBindDb = SqlHelper::ormSelectOne( myself()->_getMysql($openId), 't_sub_user_bind', array( 'org_account_id' => $accountId, ) ); $accountId = $accountBindDb ? $accountBindDb['cur_account_id'] : $accountId ; $redis = $this->_getRedis($accountId); $lastActiveTime = $redis->get(LAST_ACTIVE_TIME . $accountId); if (!empty($lastActiveTime) && $lastActiveTime > myself()->_getNowDaySeconds()){ $info['loginVal'] = 1; } // $loginDyn = SqlHelper::ormSelectOne( // myself()->_getMysql($openId), // 't_dyndata', // array( // 'account_id' => $accountId, // 'x' => TN_DAILY_LOGINS, // 'y' => 0, // ) // ); // if ($loginDyn){ // $info['loginVal'] = $loginDyn['val']; // if (myself()->_getDaySeconds($loginDyn['modifytime']) < myself()->_getNowDaySeconds()) { // $info['loginVal'] = 0; // } // } $battleDb = SqlHelper::ormSelectOne( myself()->_getMysql($openId), 't_battle', array( 'account_id' => $accountId, ) ); if ($battleDb){ $hisBattleData = json_decode($battleDb['battle_data'], true); $todayBattleData = getXVal($hisBattleData, 'today_data', array()); if (myself()->_getDaySeconds(getXVal($todayBattleData, 'modifytime', 0)) == myself()->_getNowDaySeconds()) { $info['battleTimes'] = getXVal($todayBattleData, "total_battle_times", 0); $info['winTimes'] = getXVal($todayBattleData, "total_special_win_times", 0); $info['kills'] = getXVal($todayBattleData, "total_kills_times", 0); } } $getGoldDyn = SqlHelper::ormSelectOne( myself()->_getMysql($openId), 't_dyndata', array( 'account_id' => $accountId, 'x' => TN_DAILY_GATHER_GOLD, 'y' => 0, ) ); if ($getGoldDyn){ $info['getGoldVal'] = $getGoldDyn['val']; if (myself()->_getDaySeconds($getGoldDyn['modifytime']) < myself()->_getNowDaySeconds()) { $info['getGoldVal'] = 0; } } $this->_rspData(array( 'info' => $info, )); } public function hasAnyNft() { $accountAddress = strtolower(getReqVal('account_address', '')); $ret = services\NftService::hasAnyNft($accountAddress); error_log('hasAnyNft:' . $accountAddress . ' ret:' . $ret); $this->_rspData(array( 'has_any_nft' => $ret ? 1 : 0, )); } public function nftMetaView() { $netId = getReqVal('net_id', ''); $tokenType = getReqVal('token_type', ''); $tokenId = getReqVal('token_id', ''); $info = array( "token_id" => '', "name" => "", "description" => "", "image" => "", "attributes" => array(), ); $nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, $tokenType, $tokenId); if (empty($nftDb)) { echo json_encode($info); die; } switch ($nftDb['token_type']) { case Nft::HERO_TYPE: case Nft::GCARD_HERO_TYPE: { $heroDb = Hero::findByTokenId2($tokenId); if (!$heroDb){ echo json_encode($info); die; } $heroAttrs = emptyReplace(json_decode($heroDb['wealth_attr'], true), array()); $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); $wealth = $heroResult['wealth']; $wealth_rate = $heroResult['wealth_rate']; $lucky = $heroResult['lucky']; $lucky_rate = $heroResult['lucky_rate']; $heroAbility = Hero::abilityInfo($heroDb); $heroMeta = \mt\Hero::get($heroDb['hero_id']); $NftMeta = \mt\NftDesc::getByItemId($heroDb['hero_id']); $itemMeta = \mt\Item::get($heroDb['hero_id']); $heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']); $info['token_id'] = $tokenId; $info['name'] = $heroMeta['name']; $info['description'] = $NftMeta['desc']; if ($nftDb['token_type'] == Nft::GCARD_HERO_TYPE) { $info['image'] = 'https://res2.counterfire.games/nft/video/normal/' . $heroMeta['id'] . '_c' . $this->getRealHeroQuality($heroDb) . '.mp4'; } else { $info['image'] = 'https://res2.counterfire.games/nft/video/genesis/' . $heroMeta['id'] . '_' . $this->getRealHeroQuality($heroDb) . '.mp4'; } if ($this->isWingHero($nftDb['token_id'])) { $info['image'] = 'https://res2.counterfire.games/nft/video/wing/' . $heroMeta['id'] . '_w' . $this->getRealHeroQuality($heroDb) . '.mp4'; } $info['animation_url'] = "https://res.counterfire.games/nft/video/". $heroDb['hero_id'].'_'.$this->getRealHeroQuality($heroDb).".mp4"; if ($this->isWingHero($nftDb['token_id'])) { $info['animation_url'] = "https://res.counterfire.games/nft/video/wing/". $heroDb['hero_id'].'_w'.$this->getRealHeroQuality($heroDb).".mp4"; } array_push($info['attributes'],array( "trait_type" => "Tier", "value" => intval($this->getRealHeroQuality($heroDb)), )); array_push($info['attributes'],array( "trait_type" => "Active Days", "value" => $heroAtteMeta['validTime'], )); array_push($info['attributes'],array( "trait_type" => "Wealth Value", "value" => floor($wealth * (1+$wealth_rate)), )); array_push($info['attributes'],array( "trait_type" => "Luck Value", "value" => floor($lucky * (1+$lucky_rate)), )); array_push($info['attributes'],array( "trait_type" => "Chip Slots", "value" => 0 )); array_push($info['attributes'],array( "trait_type" => "Combat Ability I", "value" => 0 )); array_push($info['attributes'],array( "trait_type" => "Combat Ability II", "value" => 0 )); } break; case Nft::GOLD_BULLION_TYPE: { $nftMeta = \mt\NftDesc::getByItemId($nftDb['item_id']); $info['token_id'] = $tokenId; $info['name'] = $nftMeta['name']; $info['description'] = $nftMeta['desc']; $info['image'] = "https://res2.counterfire.games/nft/meta/".$nftDb['item_id'].".png"; } break; } //error_log(json_encode($info)); myself()->_rspData($info); } public function nftDetailList() { $rspObj = array( 'nfts' => array() ); $data = file_get_contents('php://input'); $dataJson = json_decode($data, true); if (count($dataJson['nfts']) > 20) { myself()->_rspErr(1, 'nfts count error'); return; } foreach ($dataJson['nfts'] as $row) { $netId = $row['net_id']; $contractAddress = $row['contract_address']; $tokenId = $row['token_id']; $nftDb = Nft::getNftByNetIdContractAddressTokenId($netId, $contractAddress, $tokenId); if (!empty($nftDb)) { $info = array(); $this->internalNftDetail($netId, $nftDb, $info); array_push($rspObj['nfts'], $info); } } myself()->_rspData($rspObj); } public function nftDetailByContractAddress() { $contractAddress = getReqVal('contract_address', ''); $netId = getReqVal('net_id', ''); $tokenId = getReqVal('token_id', ''); $nftDb = Nft::getNftByNetIdContractAddressTokenId($netId, $contractAddress, $tokenId); $info = array(); //error_log(json_encode($_REQUEST)); $this->internalNftDetail($netId, $nftDb, $info); //error_log(json_encode($info)); myself()->_rspData($info); } public function nftDetailByTokenType() { $netId = getReqVal('net_id', ''); $tokenType = getReqVal('token_type', ''); $tokenId = getReqVal('token_id', ''); $nftDb = Nft::getNftByNetIdTokenTypeTokenId($netId, $tokenType, $tokenId); $info = array(); //error_log(json_encode($_REQUEST)); $this->internalNftDetail($netId, $nftDb, $info); //error_log(json_encode($info)); myself()->_rspData($info); } private function internalNftDetail($netId, &$nftDb, &$info) { $onSale = $this->nftIsOnSale($nftDb['net_id'], $nftDb['contract_address'], $nftDb['token_id']); $info = array( 'net_id' => $netId, 'contract_address' => '', 'token_id' => '', 'owner_address' => '', 'meta_url' => '', 'name' => '', 'item_id' => 0, 'type' => 0, 'image' => '', 'on_sale' => $onSale, 'detail' => array(), 'last_lock_time' => 0, ); if (!empty($nftDb)) { if ($nftDb['owner_address'] == LOCK_CONTRACT_ADDRESS || $nftDb['owner_address'] == ETH_LOCK_CONTRACT_ADDRESS) { $info['last_lock_time'] = $nftDb['last_lock_time']; } $this->internalGetNftDetail($nftDb, $info); } } private function internalGetNftDetail($nftDb, &$info) { $info['contract_address'] = $nftDb['contract_address']; $info['token_id'] = $nftDb['token_id']; $info['owner_address'] = $nftDb['owner_address']; switch ($nftDb['token_type']) { case Nft::HERO_TYPE: case Nft::GCARD_HERO_TYPE: { $heroDb = Hero::findByTokenId2($nftDb['token_id']); if ($heroDb) { $heroAttrs = emptyReplace(json_decode($heroDb['wealth_attr'], true), array()); $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); $wealth = $heroResult['wealth']; $wealth_rate = $heroResult['wealth_rate']; $lucky = $heroResult['lucky']; $lucky_rate = $heroResult['lucky_rate']; $heroAbility = Hero::abilityInfo($heroDb); $heroMeta = \mt\Hero::get($heroDb['hero_id']); if ($heroMeta) { $itemMeta = \mt\Item::get($heroDb['hero_id']); $heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']); $info['meta_url'] = NFT_META_URL . '/hero/meta/' . $nftDb['net_id'] . '/' . $nftDb['token_id']; $info['name'] = $heroMeta['name']; $info['item_id'] = $heroMeta['id']; $info['type'] = $nftDb['token_type']; //$info['image'] = 'https://res2.counterfire.games/nft/meta/' . $heroMeta['id'] . '_' . $this->getRealHeroQuality($heroDb) . '.gif'; if ($nftDb['token_type'] == Nft::GCARD_HERO_TYPE) { $info['image'] = 'https://res2.counterfire.games/nft/video/normal/' . $heroMeta['id'] . '_c' . $this->getRealHeroQuality($heroDb) . '.mp4'; } else { $info['image'] = 'https://res2.counterfire.games/nft/video/genesis/' . $heroMeta['id'] . '_' . $this->getRealHeroQuality($heroDb) . '.mp4'; } if ($this->isWingHero($nftDb['token_id'])) { $info['image'] = 'https://res2.counterfire.games/nft/video/wing/' . $heroMeta['id'] . '_w' . $this->getRealHeroQuality($heroDb) . '.mp4'; } $info['detail']['quality'] = $this->getRealHeroQuality($heroDb); $info['detail']['max_mining_days'] = $heroAtteMeta['validTime']; $info['detail']['wealth'] = floor($wealth * (1+$wealth_rate)); $info['detail']['lucky'] = floor($lucky * (1+$lucky_rate)); $info['detail']['hp'] = $heroAbility['hp']; $info['detail']['atk'] = $heroAbility['attack']; $info['detail']['def'] = $heroAbility['defence']; $info['detail']['block'] = $heroAbility['block']; $info['detail']['crit'] = $heroAbility['critical']; $this->fillHeroDetail($heroDb, $info); } } } break; case Nft::GOLD_BULLION_TYPE: { $nftMeta = \mt\NftDesc::getByItemId($nftDb['item_id']); if ($nftMeta) { $info['meta_url'] = NFT_META_URL . '/gold_bullion/meta/' . $nftDb['net_id'] . '/' . $nftDb['token_id']; $info['name'] = $nftMeta['name']; $info['item_id'] = $nftMeta['item_id']; $info['type'] = $nftDb['token_type']; $info['image'] = 'https://res2.counterfire.games/nft/meta/' . $nftMeta['item_id'] . '.png'; $info['detail']['gold_coins'] = $this->getGoldBullionGoldNum($nftDb['item_id']); } } break; case Nft::FOUNDER_TAG_TYPE: { $info['meta_url'] = 'https://nftmint.counterfire.games/nft/202403/' . $nftDb['token_id']; $info['name'] = 'Founder’s Tag #1'; $info['item_id'] = 0; $info['quality'] = $nftDb['quality']; $info['type'] = $nftDb['token_type']; $info['image'] = 'https://gateway.pinata.cloud/ipfs/QmNcUxWcNF85mx6aQp7PVNWJ89d9PqMpaHUT9vQTSTatGq'; switch ($nftDb['quality']) { case 1: { $info['image'] = 'https://gateway.pinata.cloud/ipfs/QmNcUxWcNF85mx6aQp7PVNWJ89d9PqMpaHUT9vQTSTatGq'; } break; case 2: { $info['image'] = 'https://gateway.pinata.cloud/ipfs/QmctTzuks35UTTEQS2rx7fbq8gfQZvHLQL3sjSEZck59es'; } break; case 3: { $info['image'] = 'https://gateway.pinata.cloud/ipfs/QmfCL6uncbrYnwgZiqcgYcBgL6L2WtNC6m3UTooMLHKxyk'; } break; } } break; } } private function getGoldBullionGoldNum($itemId) { switch ($itemId) { case V_ITEM_GOLD_BULLION_1W: { return 1000; } break; case V_ITEM_GOLD_BULLION_10W: { return 10000 * 1; } break; default: { return 0; } } } private function nftIsOnSale($netId, $contractAddress, $tokenId) { $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_order', array( 'net_id' => $netId, 'contract_address' => $contractAddress, 'token_id' => $tokenId, 'status' => 'ACTIVE', ) ); return $row ? 1 : 0; } private function getRealHeroQuality($heroDb) { $quality = $heroDb['quality'];; /* if ($heroDb['createtime'] <= 1719985966) { } else { $quality = $quality - 1; if ($quality <= 0) { $quality = 1; } }*/ $quality = $quality - 1; if ($quality <= 0) { $quality = 1; } return $quality; } public function getHeroList() { $accountId = getReqVal('account_id', ''); $rows = SqlHelper::ormSelect( myself()->_getMysql($accountId), 't_hero', array( 'account_id' => $accountId, ) ); $rspData = array( 'rows' => array() ); foreach ($rows as $row) { if ($row['quality'] <= 1) { continue; } $info = array( 'uniid' => '', 'net_id' => 0, 'contract_address' => '', 'token_id' => '', 'owner_address' => '', 'meta_url' => '', 'name' => '', 'item_id' => 0, 'type' => 0, 'image' => '', 'on_sale' => 0, 'detail' => array() ); $heroDb = $row; $info['uniid'] = $heroDb['idx']; $heroAttrs = emptyReplace(json_decode($heroDb['wealth_attr'], true), array()); $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); $wealth = $heroResult['wealth']; $wealth_rate = $heroResult['wealth_rate']; $lucky = $heroResult['lucky']; $lucky_rate = $heroResult['lucky_rate']; $heroAbility = Hero::abilityInfo($heroDb); $heroMeta = \mt\Hero::get($heroDb['hero_id']); if ($heroMeta) { $itemMeta = \mt\Item::get($heroDb['hero_id']); $heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']); //$info['meta_url'] = NFT_META_URL . '/hero/meta/' . $nftDb['net_id'] . '/' . $nftDb['token_id']; $info['name'] = $heroMeta['name']; $info['item_id'] = $heroMeta['id']; $info['type'] = Nft::HERO_TYPE; $info['image'] = 'https://res2.counterfire.games/nft/video/normal/' . $heroMeta['id'] . '_c' . $this->getRealHeroQuality($heroDb) . '.mp4'; $info['on_lock'] = $heroDb['seal_type']; $info['detail']['quality'] = $this->getRealHeroQuality($heroDb); $info['detail']['max_mining_days'] = $heroAtteMeta['validTime']; $info['detail']['wealth'] = floor($wealth * (1+$wealth_rate)); $info['detail']['lucky'] = floor($lucky * (1+$lucky_rate)); $info['detail']['hp'] = $heroAbility['hp']; $info['detail']['atk'] = $heroAbility['attack']; $info['detail']['def'] = $heroAbility['defence']; $info['detail']['block'] = $heroAbility['block']; $info['detail']['crit'] = $heroAbility['critical']; $this->fillHeroDetail($heroDb, $info); } array_push($rspData['rows'], $info); } myself()->_rspData($rspData); } private function fillHeroDetail($heroDb, $info) { $info['detail']['chip_slots'] = 0; $info['detail']['combat_ability_1'] = ''; $info['detail']['combat_ability_2'] = ''; $randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); $i = 1; foreach ($randAttr as $attr) { if (!isset($attr['new_attr']) || !$attr['new_attr']) { continue; } $attrMeta = myself()->_callMtStatic('AttributeList', 'get', $attr['attr_id']); if ($attrMeta) { $langMeta = myself()->_callMtStatic('Language', 'get', $attrMeta['language']); if ($langMeta) { switch ($attrMeta['dispType']) { case 1: { $info['detail']['combat_ability_' . $i] = $langMeta['en'] . sprintf('%d', $attr['val']); } break; case 2: { $info['detail']['combat_ability_' . $i] = $langMeta['en'] . sprintf('%.2f', $attr['val']); } break; case 3: { $info['detail']['combat_ability_' . $i] = $langMeta['en'] . sprintf('%.4f', $attr['val']); } break; } ++$i; if ($i >= 2) { break; } } } } } private function isWingHero($tokenId) { return $tokenId > 6240603010001668 && $tokenId <= 6240603010002168; } }