diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 2ed82841..39c00db2 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -166,8 +166,6 @@ CREATE TABLE `t_hero` ( `last_pve_get_ceg_time` bigint NOT NULL DEFAULT '0' COMMENT '最后pve获取金币的时间', `today_mission_get_ceg` bigint NOT NULL DEFAULT '0' COMMENT '悬赏任务获得金币', `last_mission_get_ceg_time` bigint NOT NULL DEFAULT '0' COMMENT '最后悬赏任务获取金币的时间', - `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', - `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id', `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count', `activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1:已初始激活', @@ -177,7 +175,10 @@ CREATE TABLE `t_hero` ( `seal_type` int(11) NOT NULL DEFAULT '0' COMMENT '0:未封存 1:已封存', `unseal_time` int(11) NOT NULL DEFAULT '0' COMMENT '解开封时间', `is_old` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:展示红点 1:不用展示 ', - + `gold_times` int(11) NOT NULL DEFAULT '0' COMMENT '打金次数 ', + `gold_modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '打金时间 ', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), UNIQUE KEY `token_id` (`token_id`), KEY `account_id` (`account_id`) @@ -1940,6 +1941,7 @@ CREATE TABLE `t_box_alloc` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `room_uuid` varchar(60) NOT NULL COMMENT '公告标题', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT 'account_id', + `phase` int(11) NOT NULL DEFAULT '0' COMMENT '阶段', `used_num` int(11) NOT NULL DEFAULT '0' COMMENT '已消耗的箱子数', `box_num` int(11) NOT NULL DEFAULT '0' COMMENT '分配的箱子数', `return_account_id` varchar(60) CHARACTER SET utf8 NOT NULL DEFAULT '' COMMENT 'return_account_id', @@ -2118,6 +2120,7 @@ CREATE TABLE `t_user_invitation_code_bind` ( ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `t_user_bind_gold_record` -- @@ -2134,4 +2137,5 @@ CREATE TABLE `t_user_bind_gold_record` ( `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -/*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file +/*!40101 SET character_set_client = @saved_cs_client */; + diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index 50ed53d1..5690cae0 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -15,6 +15,7 @@ require_once('services/BattleDataService.php'); require_once('services/TameBattleDataService.php'); require_once('services/RoomBattleDataService.php'); require_once('services/FormulaService.php'); +require_once('services/BattleBoxService.php'); require_once('mt/RankSeason.php'); require_once('mt/Robot.php'); require_once('mt/Skill.php'); @@ -1308,8 +1309,7 @@ class BattleController extends BaseAuthedController { $r->setPx(DEC_BATTLE_TICKET . $roomUuid, 1, 1000 * 3600); } - public function requestAllocBoxNum() - { + public function requestAllocBoxNum() { if (!myself()->_switchIsOpen('bigEventBoxDrop')) { myself()->_rspData(array( 'box_num' => 0 @@ -1324,7 +1324,6 @@ class BattleController extends BaseAuthedController { 'room_uuid' => $roomUuid, ) ); - $boxNum = 0; if (!empty($row)) { if ($row['createtime'] > myself()->_getNowDaySeconds()) { $boxNum = $row['box_num']; @@ -1334,40 +1333,10 @@ class BattleController extends BaseAuthedController { )); return; } - $alreadyAllocBoxNum = $this->getAlreadyAllocBoxNum(); - $dailyMaxNum = mt\Parameter::getVal('battle_event_loot_daily_max', 0); - $allocableNum = intval($dailyMaxNum - $alreadyAllocBoxNum); - $lstVal = mt\Parameter::getListValue('battle_event_loot_per_game'); - if ($allocableNum <= 0 || empty($lstVal) || count($lstVal) < 2) { - myself()->_rspData(array( - 'box_num' => 0 - )); - return; - } - $rnd = rand($lstVal[0], $lstVal[1]); - if ($rnd <= 0) { - myself()->_rspData(array( - 'box_num' => 0 - )); - return; - } - $boxNum = min($rnd, $allocableNum); - SqlHelper::insert( - $this->_getSelfMysql(), - 't_box_alloc', - array( - 'room_uuid' => $roomUuid, - 'account_id' => myself()->_getAccountId(), - 'box_num' => $boxNum, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - ) - ); - $this->incAlreadyAllocBoxNum($boxNum); + $boxNum = services\BattleBoxService::allocBox($roomUuid); myself()->_rspData(array( 'box_num' => $boxNum )); - return; } public function requestReturnBoxNum() @@ -1398,28 +1367,10 @@ class BattleController extends BaseAuthedController { 'return_time' => myself()->_getNowTime(), ) ); - $this->incAlreadyAllocBoxNum(-max(0, $allocBoxNum - $usedNum)); + services\BattleBoxService::incAlreadyAllocBoxNum($row['phase'], + $row['createtime'], + -max(0, $allocBoxNum - $usedNum)); myself()->_rspOk(); } - private function getAlreadyAllocBoxNum() - { - $key = 'box_daily_already_alloc_num:' . myself()->_getNowDaySeconds(); - $r = $this->_getRedis($key); - $num = $r->get($key); - return empty($num) ? 0 : $num; - } - - private function incAlreadyAllocBoxNum($val) - { - $key = 'box_daily_already_alloc_num:' . myself()->_getNowDaySeconds(); - $r = $this->_getRedis($key); - $num = intval($r->get($key)); - if (empty($num)) { - $r->setPx($key, $val, 1000 * 3600 * 24 * 7); - } else { - $r->setPx($key, $num + $val, 1000 * 3600 * 24 * 7); - } - } - } diff --git a/webapp/controller/ToolsController.class.php b/webapp/controller/ToolsController.class.php index 24cdda7b..46b9afe1 100644 --- a/webapp/controller/ToolsController.class.php +++ b/webapp/controller/ToolsController.class.php @@ -3,11 +3,13 @@ require_once('phpcommon/bignumber.php'); require_once('phpcommon/sqlhelper.php'); require_once('services/BlockChainService.php'); +require_once('services/BattleBoxService.php'); require_once('models/BuyRecord.php'); use models\Battle; use phpcommon\SqlHelper; use services\BlockChainService; +use services\BattleBoxService; use models\BuyRecord; class ToolsController extends BaseController { @@ -489,4 +491,34 @@ class ToolsController extends BaseController { echo $checkSql2; } + public function battleBoxAlloc() + { + $phase = getReqVal('phase', ''); + $day = 0; + BattleBoxService::internalClear($phase, $day); + BattleBoxService::allocBox(myself()->_getNowTime()); + BattleBoxService::dump($phase, $day); + } + + public function battleBoxDump() + { + $phase = getReqVal('phase', ''); + $day = getReqVal('day', ''); + BattleBoxService::dump($phase, $day); + } + + public function battleBoxClear() + { + $phase = getReqVal('phase', ''); + $day = getReqVal('day', ''); + BattleBoxService::clear($phase, $day); + } + + public function battleBoxSet() + { + $phase = getReqVal('phase', ''); + $day = getReqVal('day', ''); + BattleBoxService::set($phase, $day); + } + } diff --git a/webapp/mt/MapMode.php b/webapp/mt/MapMode.php index e33f1cb6..7cca86d5 100644 --- a/webapp/mt/MapMode.php +++ b/webapp/mt/MapMode.php @@ -123,6 +123,30 @@ class MapMode return !empty($meta['daily_open_time_2']) && !empty($meta['daily_end_time_2']); } + public static function getCurrentBoxDropInfo(&$mapModeMeta, &$phase, &$startTime, &$endTime) + { + self::traverseMeta(function ($meta) + use (&$mapModeMeta, &$phase, &$startTime, &$endTime) { + if ($meta['mapMode'] == self::TREASURE_BOX_MODE) { + if (self::configedDailyTimeLimit1($meta)) { + $mapModeMeta = $meta; + $phase = 1; + $startTime = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $meta['daily_open_time'])); + $endTime = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $meta['daily_end_time'])); + return false; + } + if (self::configedDailyTimeLimit2($meta)) { + $mapModeMeta = $meta; + $phase = 2; + $startTime = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $meta['daily_open_time2'])); + $endTime = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $meta['daily_end_time2'])); + return false; + } + } + return true; + }); + } + protected static function getMetaList() { if (!self::$metaList) { diff --git a/webapp/services/BattleBoxService.php b/webapp/services/BattleBoxService.php new file mode 100644 index 00000000..eaf55b49 --- /dev/null +++ b/webapp/services/BattleBoxService.php @@ -0,0 +1,240 @@ +_switchIsOpen('bigEventBoxDrop')) { + return 0; + } + $boxNum = 0; + + $mapModeMeta = null; + $currPhase = 0; + $startTime = 0; + $endTime = 0; + + $minNum = 0; + $maxNum = 0; + $maxNumLimit = 5000; + $completionDegree = 0; + mt\MapMode::getCurrentBoxDropInfo($mapModeMeta, $currPhase, $startTime, $endTime); + $maxLst0 = mt\Parameter::getListValue('battle_event_loot_daily_period_max_0'); + $maxLst1 = mt\Parameter::getListValue('battle_event_loot_daily_period_max_1'); + if (count($maxLst0) != 2 || count($maxLst1) != 2) { + return 0; + } + if ($currPhase < 1 || $currPhase > 2) { + return 0; + } + $minNum = $maxLst0[$currPhase]; + $maxNum = $maxLst0[$currPhase]; + + error_log(json_encode(array( + 'mapNodeMeta' => $mapModeMeta, + 'currPhase' => $currPhase, + 'startTime' => $startTime, + 'endTime' => $endTime, + 'maxLst0' => $maxLst0, + 'maxLst1' => $maxLst1, + ))); + + $allocableNum = self::getDailyPhaseAllocNum($currPhase, myself()->_getNowDaySeconds()); + $alreadyAllocNum = self::getDailyPhaseAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds()); + if ($allocableNum <= 0) { + $yesterDayTime = myself()->_getNowDaySeconds() - 3600 * 24; + $yesterDayDropLastTime = self::getDailyPhaseDropLastTime($currPhase, $yesterDayTime); + $yesterDayDropTotal = self::getDailyPhaseDropTotalNum($currPhase, $yesterDayTime); + $yesterDayAllocNum = self::getDailyPhaseAllocNum($currPhase, $yesterDayTime); + if ($yesterDayAllocNum <= 0) { + $allocableNum = $maxNum; + } else { + if ($yesterDayDropTotal >= $yesterDayAllocNum) { + //掉完了 + $costTime = myself()->_getDaySecondsOffset($yesterDayDropLastTime) - $startTime; + if ($costTime <= 0) { + $completionDegree = 1; + } else { + $completionDegree = ($endTime - $startTime) / $costTime; + } + error_log(json_encode(array( + 'yesterDayDropLastTime' => $yesterDayDropLastTime, + 'yesterDayDropLastTime2' => myself()->_getDaySecondsOffset($yesterDayDropLastTime), + 'startTime' => $startTime, + 'costTime' => $costTime, + 'completionDegree' => $completionDegree, + ))); + } else { + //没掉完 + $completionDegree = $yesterDayDropTotal / $yesterDayAllocNum; + } + $allocableNum = min($maxNumLimit, $yesterDayAllocNum * $completionDegree); + } + if ($allocableNum > 0) { + self::setDailyPhaseAllocNum($currPhase, myself()->_getNowDaySeconds(), $allocableNum); + } + } else { + $allocableNum = max(0, $allocableNum - $alreadyAllocNum); + } + if ($allocableNum > 0) { + $lstVal = mt\Parameter::getListValue('battle_event_loot_per_game'); + if (!($allocableNum <= 0 || empty($lstVal) || count($lstVal) < 2)) { + $rnd = rand($lstVal[0], $lstVal[1]); + if ($rnd > 0) { + $boxNum = min($rnd, $allocableNum); + } + } + } + if ($boxNum > 0) { + if (getReqVal('c', '') != 'Tools') { + SqlHelper::insert( + myself()->_getSelfMysql(), + 't_box_alloc', + array( + 'room_uuid' => $roomUuid, + 'account_id' => myself()->_getAccountId(), + 'phase' => $currPhase, + 'box_num' => $boxNum, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + self::incAlreadyAllocNum($currPhase, myself()->_getNowDaySeconds(), $boxNum); + } + return $boxNum; + } + + public static function dump($phase, $day) + { + $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; + $data = array( + 'phase' => $phase, + 'drop_last_time' => self::getDailyPhaseDropLastTime($phase, $daySeconds), + 'drop_total' => self::getDailyPhaseDropTotalNum($phase, $daySeconds), + 'alloc_num' => self::getDailyPhaseAllocNum($phase, $daySeconds), + 'already_alloced_num' => self::getDailyPhaseAlreadyAllocNum($phase, $daySeconds), + ); + myself()->_rspData($data); + } + + public static function internalClear($phase, $day) + { + $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; + self::getDailyPhaseDropLastTime($phase, $daySeconds, 0); + self::setDailyPhaseDropTotalNum($phase, $daySeconds, 0); + self::setDailyPhaseAllocNum($phase, $daySeconds, 0); + self::setDailyPhaseAlreadyAllocNum($phase, $daySeconds, 0); + } + + public static function clear($phase, $day) + { + self::internalClear($phase, $day); + self::dump($phase, $day); + } + + public static function set($phase, $day) + { + $daySeconds = myself()->_getNowDaySeconds() + $day * 3600 * 24; + self::setDailyPhaseDropLastTime($phase, $daySeconds, getReqVal('drop_last_time', 0)); + self::setDailyPhaseDropTotalNum($phase, $daySeconds, getReqVal('drop_total', 0)); + self::setDailyPhaseAllocNum($phase, $daySeconds, getReqVal('alloc_num', 0)); + self::setDailyPhaseAlreadyAllocNum($phase, $daySeconds, getReqVal('already_alloced_num', 0)); + self::dump($phase, $day); + } + + private static function getDailyPhaseDropLastTime($phase, $time) + { + $key = self::DAILY_PHASE_DROP_LAST_TIME_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $lastTime = $r->get($key); + return empty($lastTime) ? 0 : $lastTime; + } + + private static function getDailyPhaseDropTotalNum($phase, $time) + { + $key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $num = $r->get($key); + return empty($num) ? 0 : $num; + } + + private static function getDailyPhaseAllocNum($phase, $time) + { + $key = self::DAILY_PHASE_ALLOC_NUM_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $num = $r->get($key); + return empty($num) ? 0 : $num; + } + + private static function setDailyPhaseDropLastTime($phase, $time, $val) + { + $key = self::DAILY_PHASE_DROP_LAST_TIME_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $r->setPx($key, $val, 1000 * 3600 * 24 * 7); + } + + private static function setDailyPhaseDropTotalNum($phase, $time, $val) + { + $key = self::DAILY_PHASE_DROP_TOTAL_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $r->setPx($key, $val, 1000 * 3600 * 24 * 7); + } + + private static function setDailyPhaseAllocNum($phase, $time, $val) + { + $key = self::DAILY_PHASE_ALLOC_NUM_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $r->setPx($key, $val, 1000 * 3600 * 24 * 7); + } + + private static function setDailyPhaseAlreadyAllocNum($phase, $time, $val) + { + $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $r->set($key, $val); + } + + private static function getDailyPhaseAlreadyAllocNum($phase, $time) + { + $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $num = $r->get($key); + return empty($num) ? 0 : $num; + } + + public static function incAlreadyAllocNum($phase, $time, $val) + { + $key = self::DAILY_PHASE_ALREADY_ALLOC_NUM_KEY . $phase . ':' . $time; + $r = myself()->_getRedis($key); + $num = intval($r->get($key)); + if (empty($num)) { + $r->setPx($key, $val, 1000 * 3600 * 24 * 7); + } else { + $r->setPx($key, $num + $val, 1000 * 3600 * 24 * 7); + } + } + +} diff --git a/webapp/services/RoomBattleDataService.php b/webapp/services/RoomBattleDataService.php index 654753c6..df519a8a 100644 --- a/webapp/services/RoomBattleDataService.php +++ b/webapp/services/RoomBattleDataService.php @@ -142,17 +142,17 @@ class RoomBattleDataService extends BaseService { } } + $battleSingleDb = BattleSettlement::findSingle($this->battleSettlementDb['battle_uuid']); if ($this->mapMode == mt\MapMode::TREASURE_BOX_MODE && $member['move_distance'] <= 2000 ){ error_log("金币模式:消极战斗"); }else{ - $this->_getBattleRewards($userDb,$heroDb,$battleScore,$myTeamScoreAvg,$myTeamScore,$member['reward'], $member); + $this->_getBattleRewards($battleSingleDb, $userDb,$heroDb,$battleScore,$myTeamScoreAvg,$myTeamScore,$member['reward'], $member); myself()->_addItems($member['reward'], $awardService,$propertyChgService); if ($this->mapMode == mt\MapMode::GOLD_MODE){ $member['today_hero_battles'] = $heroDb['idx'] . '|' .myself()->_getDailyV(TN_DAILY_GOLD_MODE_BATTLE_TIMES,$heroDb['idx']); } } - $battleSingleDb = BattleSettlement::findSingle($this->battleSettlementDb['battle_uuid']); if ($battleSingleDb){ $battleSingleData = emptyReplace(json_decode($battleSingleDb['data'], true), array()); $battleSingleData['reward'] = $member['reward']; @@ -177,7 +177,7 @@ class RoomBattleDataService extends BaseService { } - public function _getBattleRewards($userDb,$heroDb,$battleScore,$teamScoreAvg,$teamScore,&$reward, $member){ + public function _getBattleRewards($battleSingleDb, $userDb,$heroDb,$battleScore,$teamScoreAvg,$teamScore,&$reward, $member){ error_log('settlementReward -> _getBattleRewards'); $mapModeMeta = mt\MapMode::findByMapMode($this->mapMode); $teamRank = getXVal($this->teamData,'pvp_team_rank', 0); @@ -229,7 +229,7 @@ class RoomBattleDataService extends BaseService { } //宝箱掉落 - $this->_dropBox($rewardMeta,$teamRank,$reward,$member); + $this->_dropBox($battleSingleDb, $rewardMeta,$teamRank,$reward,$member); } } @@ -328,7 +328,7 @@ class RoomBattleDataService extends BaseService { return $gold; } - private function _dropBox($rewardMeta,$teamRank,&$reward,$member){ + private function _dropBox($battleSingleDb, $rewardMeta,$teamRank,&$reward,$member){ //宝箱掉落 $chestLootProbArr = explode(";",$rewardMeta['chestLootProb']); $rate = isset($chestLootProbArr[$teamRank-1]) ? $chestLootProbArr[$teamRank-1] : 0;