_rspErr(1, 'Please enter instructions'); return; } $cmd = $cmds[0]; $params = count($cmds) > 1 ? array_slice($cmds, 1) : array(); $cmdHash = array( '.help' => function () use($params) { $this->help($params); }, '.additem' => function () use($params) { $this->addItem($params); }, '.addnft' => function () use($params) { $this->addNft($params); }, '.addtili' => function () use($params) { $this->addTili($params); }, '.getsystime' => function () use($params) { $this->getSysTime($params); }, '.setsystime' => function () use($params) { $this->setSysTime($params); }, '.reset_mission' => function () use($params) { $this->resetMission($params); }, '.addtest' => function () use($params) { $this->addDyndata($params); }, '.loot' => function () use($params) { $this->lootTest($params); } ); $func = getXVal($cmdHash, $cmd); if ($func) { $func($params); } else { $this->_rspErr(2, 'Unrecognized instruction'); return; } } private function help($params) { $this->_rspData(array( 'text' => <<_addItems(array( array( 'item_id' => $itemId, 'item_num' => $itemNum ) ), $awardService, $propertyChgService); $this->_rspData(array( 'text' => 'add item success', 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), )); } private function addNft($params) { $itemId = getXVal($params, 0, 0); $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); $itemMeta = mt\Item::get($itemId); if ($itemMeta) { $tokenType = Nft::getTokenType($itemMeta); if ($tokenType == Nft::NONE_TYPE) { myself()->_rspErr(1, 'param item_id error'); return; } else { SqlHelper::insert( myself()->_getMarketMysql(), 't_nft', array( 'token_id' => Nft::genTempTokenId(), 'token_type' => $tokenType, 'game_id' => 2006, 'item_id' => $itemId, 'owner_address' => myself()->_getAddress(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); } } else { myself()->_rspErr(1, 'param item_id error'); return; } $this->_rspData(array( 'text' => 'add nft success', 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), )); } private function addTili($params) { $heroId = getXVal($params, 0, 0); $tili = getXVal($params, 1, 0); Hero::update($heroId, array( 'hero_tili' => "hero_tili + ${tili}" )); $propertyChgService->addHeroChg(); $this->_rspData(array( 'text' => 'add item success', 'award' => $awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), )); } private function getSysTime($params) { $sysTime = phpcommon\timestamp_to_datetime(phpcommon\getNowTime()); $this->_rspData(array( 'text' => $sysTime, )); } private function setSysTime($params) { if (!defined('GLOBAL_TIME_OFFSET_KEY')) { die('不支持设置系统时间'); return; } $newtime = strtotime($_REQUEST['newtime']); if ($newtime <= 0) { die('时间格式错误'); return; } $time_offset = $newtime - phpcommon\getRealTime(); $r = new phpcommon\Redis(array( 'host' => '127.0.0.1', 'port' => 6379, 'passwd' => '' )); $r->set(GLOBAL_TIME_OFFSET_KEY, $time_offset); } private function resetMission($params) { myself()->_getSelfMysql()->execScript('DELETE FROM t_mission;'); myself()->_getSelfMysql()->execScript('DELETE FROM t_bigdata;'); myself()->_rspOk(); } private function addDyndata($params){ $type = getXVal($params, 0, 0); $num = getXVal($params, 1, 0); switch ($type){ case 1 : { myself()->_incV(TN_TOTAL_KILLS_NUM,0,$num); } break; case 2 : { myself()->_incV(TN_TOTAL_STAR_NUM,0,$num); } break; case 3 : { myself()->_incV(TN_TOTAL_DIAMOND_CONSUME,0,$num); } break; case 4 : { myself()->_incV(TN_TOTAL_CEG_CONSUME,0,$num); } } } private function lootTest($params){ $lucky = getXVal($params, 0, 0); $itemId = getXVal($params, 1, 0); $itemNum = getXVal($params, 2, 0); $itemMeta = mt\Item::get($itemId); if (!$itemMeta || $itemMeta['type'] != mt\Item::BATTLE_REWARD_BOX) { $this->_rspErr(2, 'config error'); return; } $lootMeta = mt\LootConfig::find($itemMeta['loot']); if ($lootMeta['isAffected']){ $luckyParam = \mt\Parameter::getVal('economy_account_luck_K',0); $luckyMaxPro = \mt\Parameter::getVal('economy_account_luck_E',0); $prob = $luckyMaxPro * ($lucky / ($lucky+$luckyParam)); for ($i=0; $i<$itemNum; $i++){ $times = $this->proEffect($prob,1); $temp = array( "prob" => $prob, "times" => $times ); $items = \services\LootService::dropOutItem($itemMeta['loot']); if ($times > 0){ foreach ($items as &$item){ $item['item_num'] += $item['item_num']*$times; } } array_unshift($items,$temp); TGLog::writeToLog("game_2006_api","loot",$items); } }else{ for ($i=0; $i<$itemNum; $i++){ $items = \services\LootService::dropOutItem($itemMeta['loot']); TGLog::writeToLog("game_2006_api","loot",$items); } } } private function proEffect($p,$b){ if ($p * $b > -1 && $b != 0) { $x = floor($p) * $b; $y = max($x+$b,-1); $q = ($p * $b - $y) / ($x - $y); $rnd = rand(1,100); return $rnd < $q*100 ? $x : $y; }else{ return 0; } } }